Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-05 : 18:12:36
|
Shankar Ganesh writes "Hi Is there any way can I get comma separated results from a table? I know I can save the results of a Select query in csv files thru query analyser. But I need a straight forward SQL query/SP/UDF to include it in my scripts.For example,an Employee table with columns empno, name, salaryand data like1 'Nancy' 1000.002 'Steven' 1500.003 'Andrew' 3000.00 On firing a SQL query/SP/UDF for this table, I should get1,'Nancy',1000.002,'Steven',1500.003,'Andrew',3000.00 Advance thanks for you helpThanksShankar" |
|
|
JamesT
Yak Posting Veteran
97 Posts |
Posted - 2002-03-05 : 18:26:52
|
| I know of something that may work for you but it is not very elegant. select column1, ',', column2, ',', column3, ',', etc...from tableAgain, this is ugly and not very easy to change on the fly but it should work. I would recommend using DTS. I know that will work for you as I have done it many times. |
 |
|
|
yakoo
Constraint Violating Yak Guru
312 Posts |
Posted - 2002-03-05 : 19:40:22
|
wouldnt that generate an error...you could try..SELECT Cast(empno AS VarChar) + ',''' + name + ''',' + Cast(salary AS VarChar) AS RowOutput FROM Employee you might want to look into option for cast/convert so that the decimal value for .00 is returned as well.(graz - is there a reason why the + symbol doesnt show up in the preview window?) |
 |
|
|
JamesT
Yak Posting Veteran
97 Posts |
Posted - 2002-03-06 : 12:50:20
|
| When I wrote the query (column names and table name changed to protect the innocent) and ran it it worked. It had column1, then a comma, column2, etc. No error.select column1, ',', column2, ',', column3,','from tbl_foo |
 |
|
|
|
|
|
|
|