Assume for a minute that you have a table with records that you want to quickly put into a comma separated file (fig. 1). You don’t want to create a Microsoft Integrated Service package like this. Rather you just need something quick. There is a really cool way to do this directly in a select statement in SQL 2005 and greater. It is called STUFF (you can read about it here).
[code language=”SQL”]
SELECT STUFF( (SELECT ‘, ‘ + job_code
FROM [tablename]
FOR XML PATH(”), TYPE).value(‘.’, ‘varchar(max)’)
,1, 2, ”)
[/code]
This will produce one record that looks like this.
[code language=”text”]
0002, 0004, 0005, 0006, 0008, 0011, 0017, 0018, 0020, 0023, 0027
[/code]
Hope this helps someone like it helped me.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!