开发者

Create delimited string from a row in stored procedure with unknown number of elements

开发者 https://www.devze.com 2023-01-13 16:13 出处:网络
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?

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开发者_如何学C column in another table.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号