Friday, February 24, 2012

How to use a variable in update statement?

Does anyone have insight on how I can accomplish this?

I have a table with a column called username. In that column I have a value in the form "domain_A\user". There are about 2900 records in the table. I want to change the domain portion to "domain_B"of a select few of the users based on a list. I would hope that I can use an update statement that has a variable. Then get that variable from the list I have.

Any help is greatly appreciated.update tbl set username = a.username
from tbl inner join a_list a
on tbl.username = replace(a.username, 'domain_B', 'domain_A')|||declare @.domain varchar(20)
set @.domain = 'domain_B\'
update test set jsp_name=@.domain+substring(jsp_name,10,15) where --ur where clause

No comments:

Post a Comment