Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 31st, 2008, 04: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;

  #2 (permalink)  
Old February 1st, 2008, 12:04 AM
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
  #3 (permalink)  
Old February 1st, 2008, 12:06 AM
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
  #4 (permalink)  
Old February 1st, 2008, 09: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...

)



Similar Threads
Thread Thread Starter Forum Replies Last Post
To select infinite nested element in XSLT1.0 rajatake XSLT 2 December 14th, 2006 09: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.