Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-09-24 : 09:47:56
|
| Hi, I have created the following CTE tables but would like to update AOGM_rev within cte1 with AOTAOT within cte2 Many thanks in advancewith cte1 as (select TreeYear,BusinessUnitID,Year,PeriodID,ICTypeKey,AOGM_REV from View_A_AOGM where Year = '2010' and BusinessUnitID = '01130' and YM = '2010-12'),cte2 as (select year,businessunitid,ictypekey,lk,sum(aot) as AOTAOT from View_A_AOT where Year = '2010' and BusinessUnitID = '01130' and TreeYear = '2011'and lk = '20' group by year,businessunitid,lk,ICTypeKey) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-24 : 12:07:18
|
| where do you want to update the values to?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-09-25 : 14:07:00
|
| I want to update the values of AOGM_rev within cte1wit teh values from AOTAOT within cte2 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 00:28:04
|
| [code]with cte1 as (select TreeYear,BusinessUnitID,Year,PeriodID,ICTypeKey,AOGM_REV from View_A_AOGM where Year = '2010' and BusinessUnitID = '01130' and YM = '2010-12'),cte2 as (select year,businessunitid,ictypekey,lk,sum(aot) as AOTAOT from View_A_AOT where Year = '2010' and BusinessUnitID = '01130' and TreeYear = '2011'and lk = '20' group by year,businessunitid,lk,ICTypeKey)UPDATE c1STE c1.AOGM_REV=c2.AOTAOTFROM CTE1 c1INNER JOIN CTE2 c2ON c1.BusinessUnitID = c2.BusinessUnitIDAND c1.ictypekey =c2.ictypekeyAND c1.TreeYear = c2.Year[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-09-26 : 07:33:23
|
| Thank you Visakh,That worked great :) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 07:43:00
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|