update two rows in one query

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 1
Reputation: rchokler is an unknown quantity at this point 
Solved Threads: 0
rchokler rchokler is offline Offline
Newbie Poster

update two rows in one query

 
0
  #1
May 13th, 2007
UPDATE table1
SET ID,[DESC] =
(SELECT ID,[DESC]
FROM tmptable
WHERE tmptable.ID_SUN = table1.ID_SUN)
WHEREEXISTS
( SELECT ID,[DESC]
FROM tmptable
WHERE tmptable.ID_SUN = [Table1].ID_SUN)
I tired this but i coudn't uptade tow columns at once
do i need to seperate them or i have any mistake?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 28
Reputation: cfAllie is an unknown quantity at this point 
Solved Threads: 0
cfAllie cfAllie is offline Offline
Light Poster

Re: update two rows in one query

 
0
  #2
May 13th, 2007
Yes, you need to separate them. The syntax should be more like

  1. UPDATE SomeTable
  2. SET Column1 = SomeValue1,
  3. Column2 = SomeValue2,
  4. Column3 = ....

It doesn't look like you need a subquery either. A simple join should be sufficient. Something like

  1. UPDATE t1
  2. SET t1.ID = tmp.ID,
  3. t1.[DESC] = tmp.[DESC]
  4. FROM
  5. tmptable tmp INNER JOIN table1 t1
  6. ON tmp.ID_SUN = t1.ID_SUN
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC