views:

29

answers:

1

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row?

I'm pulling one row at a time from different tables and am going to store them in a column in another table.

+1  A: 

A simple SQL query can't do anything like that. You need to specify the fields you are concatenating.

The only method that I'm aware of is to dynamincally build a query for each table.

I don't recall the structure of MSSQL2000, so I won't try to give an exact example, maybe someone else can. But there -are- system tables that contain table defintions. By parsing the contents of those system tables you can dynamically build the necessary query for each source data table.

TSQLthat writes TSQL, however, can be a bit tricky to debug and maintain :) So be careful how you structure everything...

Dems.


EDIT:

Or just do it in your client application.

Dems