User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 428,578 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,676 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 3139 | Replies: 1
Reply
Join Date: May 2007
Posts: 1
Reputation: rchokler is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rchokler rchokler is offline Offline
Newbie Poster

update two rows in one query

  #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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 28
Reputation: cfAllie is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cfAllie cfAllie is offline Offline
Light Poster

Re: update two rows in one query

  #2  
May 13th, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 11:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC