sql server - Under what circumstances does an update Join table work without a FROM statement in T-SQL? -
i trying figure out cases these 2 statements work or not work. able use statement 1 couple times project; cannot decipher difference. statement 1
update tbl1 inner join tbl2 b a.clm = b.clm set a.clm1 = case when b.clm2 = 1 11 else 2 end, b.clm2 = case when b.clm4 = 2 3 else 100 end; compared
statement 2
update set a.clm1 = case when b.clm2 = 1 11 else 2 end, b.clm2 = case when b.clm4 = 2 3 else 100 end tbl1 inner join tbl2 b a.clm = b.clm;
your statement 1 should throw error on compile. update syntax
update has followed object being updated. otherwise, sql server have no idea table in join 1 needs updated.
if refer link msdn article, you'll see syntax requires following:
- update [alias or object name]
- set statement
- from (if used alias)
- where statement
as jonnygold said, second example ideal way update join or complex queries. simple queries, can "update [object] set...where...".
Comments
Post a Comment