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)
 Dynamic SQL

Author  Topic 

erwine
Yak Posting Veteran

69 Posts

Posted - 2006-06-08 : 23:57:02
Okay, I have :
SELECT t_name, t_code FROM [TABLE1]

It will result in, let's say :
'T1','0001'
'T1','0011'
'T2','0106'
'T2','0203'

Now from the result, I actually want to do :
Update T1 set Lock = 1 where Code = '0001'
Update T1 set Lock = 1 where Code = '0011'
Update T2 set Lock = 1 where Code = '0106'
Update T2 set Lock = 1 where Code = '0203'

Any idea how to do that in one shot?
Thx for your kind attention.







... sql is fun...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-08 : 23:59:39
you can make use of xp_execresultset. However this is undocumented.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=39461&SearchTerms=xp_execresultset



KH

Go to Top of Page

erwine
Yak Posting Veteran

69 Posts

Posted - 2006-06-09 : 00:31:44
Yes..currently im using loop to execute UPDATE by using sp_executesql
Im juz thinking whether there is a way to do without looping.
thx btw..i'll read the link 1st.
:)

... sql is fun...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-09 : 01:15:27
here is another link on the sp http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13384&SearchTerms=xp_execresultset


KH

Go to Top of Page
   

- Advertisement -