Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating one table based on info from another table

Status
Not open for further replies.

sap1958

Technical User
Joined
Oct 22, 2009
Messages
138
Location
US
Here is code
select giftid,attrtype,
sum(case when gifttype in ('b','g','y') then giftjntamt else 0 end)as Gifts,
sum(case when gifttype = 'c' then giftjntamt else 0 end)as Credits
from gifts with(readpast)
left outer join attribute_VIEW with(readpast)
on attrid=giftid
where gifttype in ('b','c','g','y')
and gifteffdat >='2009-07-01'

group by giftid,attrtype
having sum(giftjntamt)>=250
sample data
giftid attrtype gifts credits
11111 Null 250 0
11211 SON24 355 122
12544 Null 125 125

I need to update all records in this query to populate SON24 in the attrtype field because all records have giving or credits of 250 or more. The field that needs updating is the attribute_VIEW field. The qualifying field is the gift field. So I need to update the attribute_VIEW table with SON24. Does the update statement go before or after the above query and how would I update when there are multiple tables involved
 
Code:
;with cte as (myCurrent Select Statement)

update V set SomeField = F.AnotherField from Attribute_View V INNER JOIN cte F on V.PK = F.FK

This is the main idea here.


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top