Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update statement

Author  Topic 

sri189
Starting Member

4 Posts

Posted - 2010-07-23 : 06:21:05
Hi,
I have to write an update stmt where i have to loop through the rows of a temptable and if the id exists i have to do the update pls help me on how to go abt this

thanks in advance

sri

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-23 : 06:24:13

update temptable
set col='some value'
where <some condition>

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sri189
Starting Member

4 Posts

Posted - 2010-07-23 : 10:32:19
how to loop thro' the table? and thn write the update

sri
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-23 : 11:39:13
Can you provide table structure of the table that is source of data and the table that needs to be updated.

If possible, provide some sample data too.
Go to Top of Page

sri189
Starting Member

4 Posts

Posted - 2010-07-26 : 05:20:20
can some one help me with the below update stmt.. id doesnt seem to work!!

UPDATE Table1 SET SALES_USER_NAME = MO.SALES_USER_NAME,
ROLENAME = MO.ROLENAME from #temptable MO1,(SELECT MO1.SALES_USER_NAME, MO1.ROLENAME FROM #temptable MO1 JOIN table1 ON
#temptable.OPPORTUNITY_ID = table1.OPPORTUNITY_ID)MO WHERE MO.OPPORTUNITY_ID = table1.OPPORTUNITY_ID

sri
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-26 : 05:29:36
Can you explain more on "doesn't seem to work!!" ? ?
The query gives you error ? It does not execute as what you have expected ?

Post some sample data and show us the expected result.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

oxegg
Starting Member

6 Posts

Posted - 2010-07-30 : 03:24:15
You can try to replace #temptable with tempdb..#temptable
Go to Top of Page
   

- Advertisement -