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:

  1. update [alias or object name]
  2. set statement
  3. from (if used alias)
  4. where statement

as jonnygold said, second example ideal way update join or complex queries. simple queries, can "update [object] set...where...".


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -