 |
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
|
|
|

January 31st, 2008, 04:10 PM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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;
|

February 1st, 2008, 12:04 AM
|
Friend of Wrox
|
|
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|

February 1st, 2008, 12:06 AM
|
Friend of Wrox
|
|
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|

February 1st, 2008, 09:30 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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...
)
|
|
 |