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
 General SQL Server Forums
 New to SQL Server Programming
 Updates all 0's to NULL

Author  Topic 

littlewing
Starting Member

33 Posts

Posted - 2008-03-20 : 11:19:22
Can someone help me with the following? I need to update all columns in a table where the value is zero with NULL where the row id's (primary keys) are between two values. I was hoping that I could do this without "hard coding" the column names as there are many columns. i.e:

UPDATE TABLENAME
FOR ALL COLUMNS
SET VALUE = NULL WHERE VALUE = 0
FOR ROWS BETWEEN n and m

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-20 : 11:24:06
UPDATE TABLENAME
SET Field1 = NULLIF(Field1,0),Field2=NULLIF(Field2,0),...
WHERE PK BETWEEN n and m
Go to Top of Page
   

- Advertisement -