MSSQL basics - comma delimited output

This is very simple for SQL but unfortunately is not out there for a google search. I wanted a comma delimited output from a mssql query. Searching google returns nothing excapt a row delimited output... not what I want.

I want each field delimited in the output as below....

name,address,color,size,yes,no,foo

It is very easy, simply use the following select statement...

select name +','+addres+','+color+','+size+','+yes+','+no+','+foo as out from customers

that statement will output each record found as the comma delimited data in a single field named out. using this on the commandline sql scripting in a batch file makes life really easy to export query data from a secured server via ftp to a different location for easy use.

yes this is really basic stuff, but almost nobody had this as a solution for comma delimited output in MSSQL

Just my way of helping the newbie.

Comments