Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 31st, 2008, 03:10 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update with nested select

Hi,

I'm trying to do an update of a table off a nested select which happens to be a union... but it doesn't work.. says that there is an error in my Update statement... If I remove the UPDATE syntax, I get data returned... Any help would be great

UPDATE Churn_FormData AS a INNER JOIN
SELECT * FROM (

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table1
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit

UNION

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table2
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit

UNION

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table3
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit
) AS b

ON a.Initiative=b.Initiative SET a.January = b.Total;

Reply With Quote
  #2 (permalink)  
Old January 31st, 2008, 11:04 PM
Friend of Wrox
 
Join Date: Oct 2007
Location: , , .
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

EXAMPLE
UPDATE DEST INNER JOIN SOURCE ON DEST.areaid = SOURCE.areaid SET DEST.areadesc = [SOURCE].[AREADESC]
WHERE DEST.areaid)=[SOURCE].[AREAID] AND DEST.areaid)=3


You try following code with paranthesis and see whether it works or not.


UPDATE Churn_FormData AS a INNER JOIN
(SELECT * FROM (

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table1
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit

UNION

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table2
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit

UNION

SELECT Initiative, CostSplit, Count(*) AS Total
FROM Table3
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit
) AS b) as c

ON a.Initiative=c.Initiative SET a.January = c.Total;


urt
Reply With Quote
  #3 (permalink)  
Old January 31st, 2008, 11:06 PM
Friend of Wrox
 
Join Date: Oct 2007
Location: , , .
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

read previous EXAMPLE as following

UPDATE DEST INNER JOIN SOURCE ON DEST.areaid = SOURCE.areaid SET DEST.areadesc = [SOURCE].[AREADESC]
WHERE DEST.areaid=[SOURCE].[AREAID] AND DEST.areaid=3



urt
Reply With Quote
  #4 (permalink)  
Old February 1st, 2008, 08:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Trying what you suggested does not work, I get a message saying:
Operation must use an updateable query.

What I'm currently doing is a 2-prong approach by copying the data into a dummy table, then doing the update from the dummy table... but I'd like to do it in 1 step...

SELECT Initiative, Total INTO TempChurn
FROM (SELECT Initiative, CostSplit, Count(*) AS Total
FROM ProactiveBcrisProvisioning
WHERE Format([SubmittedDt],"mmmm") = (SELECT Month FROM DtRange) AND Format([SubmittedDt],"yyyy") = (SELECT Year FROM DtRange) AND CostSplit = "Churn"
GROUP BY Initiative, CostSplit

UNION

etc...

)

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
To select infinite nested element in XSLT1.0 rajatake XSLT 2 December 14th, 2006 08:32 AM
selected value of nested repeater-build <select> bttrflii ASP.NET 2.0 Professional 2 September 15th, 2006 09:52 AM
Nested Loop Select Box Issue mat41 Classic ASP Basics 5 August 24th, 2004 11:02 PM
Select Box update to MySQL Jdbellmon Pro PHP 1 October 10th, 2003 12:03 PM
Select Box update to MySQL Jdbellmon PHP Databases 1 October 7th, 2003 06:45 PM



All times are GMT -4. The time now is 09:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.