SQL Server: How to update a table with values from another table -


i have 2 tables. users1:

userid holidaycity validfrom    validto 1      null        '1900-01-01' '2017-05-09' 1      null        '2017-05-09' null 2      null        '1900-01-01' '2017-05-09' 2      null        '2017-05-09' null 

users2:

userid cityid 1      33 2      55 

i need update holidaycity column first table values in cityid column second table each userid, records, where validto null, resulting table users1 be:

userid holidaycity validfrom    validto 1      null        '1900-01-01' '2017-05-09' 1      33          '2017-05-09' null 2      null        '1900-01-01' '2017-05-09' 2      55          '2017-05-09' null 

can please tell me how that?

this simple inner join

update u   set u.holidaycity=c.cityid users1 u   inner join users2 c     on u.userid = c.userid    , u.validto null 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -