954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

update two rows in one query

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?

rchokler
Newbie Poster
1 post since May 2007
Reputation Points: 10
Solved Threads: 0
 

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

UPDATE SomeTable
SET   Column1 = SomeValue1,
        Column2 = SomeValue2,
        Column3  = ....

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

UPDATE t1
SET    t1.ID = tmp.ID,
         t1.[DESC] = tmp.[DESC]
FROM   
        tmptable tmp INNER JOIN table1 t1
        ON tmp.ID_SUN = t1.ID_SUN
cfAllie
Light Poster
28 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You