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 

cgunner
Yak Posting Veteran

95 Posts

Posted - 2005-01-28 : 10:37:14
I need a little help with some data scrubbing. I have a column that I need updated with information in another column but I need the source column set to ''.

UPDATE table SET col001 = col002 where col001 = 'something'

'something' needs to be over written with col002 and after that is complete col002 needs to be set to blank. Any help would be appreciated. Thanks.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-01-28 : 10:55:29
This seems to work:

create table #temp (col1 int null, col2 int null)

insert #temp (col1) values (1)
insert #temp (col1) values (2)
insert #temp (col1) values (3)

SElect * from #temp
update #temp set
col2 = col1
,col1 = null
where col1 = 2
SElect * from #temp
Go to Top of Page

cgunner
Yak Posting Veteran

95 Posts

Posted - 2005-01-28 : 11:12:40
Thanks!
Go to Top of Page
   

- Advertisement -