Click here to Skip to main content
15,918,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Here is my script grab from net

<br />
declare @col varchar(255), @cmd varchar(max)<br />
DECLARE getinfo cursor for<br />
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'<br />
OPEN getinfo<br />
FETCH NEXT FROM getinfo into @col<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
    SELECT @cmd = 'IF EXISTS (SELECT top 1 * FROM tblDeductions WHERE [' + @col + '] IS NOT NULL) BEGIN print ''' + @col + ''' end'<br />
    exec (@cmd)<br />
    FETCH NEXT FROM getinfo into @col<br />
END<br />
CLOSE getinfo<br />
DEALLOCATE getinfo<br />


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.
Posted

1 solution

'HireMeForYourWork' ? ROTFL !!!!

If you want to save them, just declare a string variable and put them in there. If you want to skip nulls, check for null first ? Are you saying you found this code online ? Does that mean you don't understand it at all ? Why would we hire you for our work then ? You need to buy some books and read them, not just copy random code and hit a wall when it needs changing to do what you want.
 
Share this answer
 
Comments
ntrraorao 2-Aug-10 1:41am    
Can you please give an example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900