Comma Sepreted List of Column value in SqlTable

 

 

Declare @Empcodelist nvarchar(max)-- declare @Empcodelist
set @Empcodelist = '' -- first set blank in @Empcodelist
select @Empcodelist = @Empcodelist + ',' + cast(EmpCode as nvarchar(30)) from empmaster
-- our result would be -  '001','002','003',
-- remove the last ',' from the list we used substring function
set @Empcodelist = substring(@Empcodelist,2,4000)
select @Empcodelist


Advertisements
This entry was posted in Sql. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s