紧急请教SQL语句

table 如下:

 OrgID   SubOrgID  Code

1            1               1111

1            3                1212

1            4                4541

5            5                2121

5            6                1010

7            7                3212

输出如下:

1111      1111,1212,4541

2121      2121,1010

3212      3212

谢谢了。。。紧急中。。。

 

 

扬帆大鱼
浏览 558回答 2
2回答

qq_遁去的一_1

create function test_str(@id int)returns varchar(100)as begin     declare @a varchar(100)        set @a=''        select @a= @a+Code+',' from test where orid=@id --in(select distinct orid from test )        return @a endgoselect distinct left(dbo.test_str(orid),charindex(',',dbo.test_str(orid))-1) ,dbo.test_str(orid) as code from test
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server