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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update table from values from another table

Author  Topic 

tech_1
Posting Yak Master

129 Posts

Posted - 2011-09-09 : 12:11:15
Hi.

Same DB
I have a joined query which gives me back the relevant data that I need to update, with the values to update with from the join table (in this case the column rightTableType)

how would I do this?


select pi.tabletype AS 'leftTableType', publicationid, p.id, p.TableType AS 'rightTableType'
from publicationItem pi
inner join Publication p on pi.PublicationId = p.Id

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-09-09 : 12:18:17
Not clear to me which the source column is and which the destination column is, but assuming it is the table types, you can do something like this:

with cte as (

select pi.tabletype AS 'leftTableType', publicationid, p.id, p.TableType AS 'rightTableType'
from publicationItem pi
inner join Publication p on pi.PublicationId = p.Id
) update cte set leftTableType = rightTableType
Go to Top of Page
   

- Advertisement -