Sean Lange (9/17/2013)
C Hrushi (9/17/2013)
This might hep for n number of columns :*********************************************************************************************
DECLARE @Q NVARCHAR(4000),
@CName VARCHAR(255)
DECLARE ColCur CURSOR
FOR
SELECT C.name as Column_name
FROMsys.columns C
LEFT JOIN sys.tables t
on C.object_id = t.object_id
WHEREt.name = 'Your_table'
OPEN ColCur
FETCH NEXT FROM ColCur INTO @CName
WHILE(@@FETCH_STATUS =0)
BEGIN
SET @Q = 'UPDATE Your_Table SET '+@CName+' = NULL WHERE '+@CName+' ISNULL '
PRINT @Q
FETCH NEXT FROM ColCur INTO @CName
END
CLOSE ColCur
DEALLOCATE ColCur
No need for a cursor for something this simple. You can easily use the code I posted. All you need to do is add 'Update MyTable set' + [query results]
You could use STUFF to build up the comma delimited list of values, the values in this case are the column update sql strings. Then execute the string.
I agree!