TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
hiremeforyourwo
NA
10
42.5k
HOW TO SAVE PRINT VARIABLE INTO ANOTHER VARIALBE IN SQL SERVER
Aug 2 2010 12:42 AM
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.
Reply
Answers (
0
)
How to insert large no of excel sheet rows into database table? which is the best method?
SQL 2008 Text Search (FREETEXTTABLE, formsof, thesaurus )