HOW TO SAVE PRINT VARIABLE INTO ANOTHER VARIALBE IN SQL SERVER
Hi
Here is my script grab from net
declare @col varchar(255), @cmd varchar(max)
DECLARE getinfo cursor for SELECT c.name FROM sys.tables t JOIN sys.columns c ON t.Object_ID = c.Object_ID WHERE t.Name = 'tblDeductions' AND c.name like 'fld%name' OPEN getinfo
FETCH NEXT FROM getinfo into @col
WHILE @@FETCH_STATUS = 0 BEGIN SELECT @cmd = 'IF EXISTS (SELECT top 1 * FROM tblDeductions WHERE [' + @col + '] IS NOT NULL) BEGIN print ''' + @col + ''' end' exec (@cmd)
FETCH NEXT FROM getinfo into @col
END CLOSE getinfo
DEALLOCATE getinfo
The above query will display column names that are null values. But I need to save them into another variable with comma separated values.
Thanks in advance.