开发者

Retrieving SQL Relationships as a comma delimited string

I have a SQL Server 2005 database with two tables: Order, LineI开发者_运维百科tem. Each LineItem has a field called LineItemID and OrderID. I have a query that is getting all of the Order records in my database. With each Order record, I would like to retrieve a comma delimited list of LineItemIDs associated with the Order.

Is there a way to do this in SQL? I do not know how to do this.

Thank you!


Here's one example, using the name column from sys.tables, of how to construct a comma-delimited string from a column:

use master
go

SELECT Stuff((SELECT ',' + name
              FROM sys.tables
              For XML PATH ('')),1,1,'')
go
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜