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
Post a Comment