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
 SQL Server Development (2000)
 copy coulmns with filtered data

Author  Topic 

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2006-09-19 : 18:01:27
HI All, I want to copy data from one column1 to another column2 but issue I am having is column1 is of type varchar and column2 is of type int and I want to say that insert those values into column2 from column1 which are number like '12' and put null if it hits word like"unsure".
Is there way I can filter my "words" and say null into another column.

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2006-09-19 : 18:19:11
You can use a case statement:
UPDATE yourTable
SET column2 = CASE WHEN IsNumeric(column1) = 1 THEN CONVERT(int, column1) ELSE NULL END


I haven't tested it but it should to the trick with some minor tweaking.
Suggest you run it as a SELECT first to see what it will output.

HTH,

Tim
Go to Top of Page

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2006-09-20 : 10:57:51
Thanks!
Go to Top of Page
   

- Advertisement -