944,078 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 6880
  • MS SQL RSS
May 13th, 2007
0

update two rows in one query

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rchokler is offline Offline
1 posts
since May 2007
May 13th, 2007
0

Re: update two rows in one query

Yes, you need to separate them. The syntax should be more like

MS SQL Syntax (Toggle Plain Text)
  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

MS SQL Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Unverified User
cfAllie is offline Offline
28 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Query Total Asset
Next Thread in MS SQL Forum Timeline: Checking for banned words





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC