create TABLE [dbo].[t_caishu](
[c1] [int] NOT NULL CONSTRAINT [DF_t_caishu_c1] DEFAULT ((0)),
[c2] [int] NOT NULL CONSTRAINT [DF_t_caishu_c2] DEFAULT ((0)),
[c3] [int] NOT NULL CONSTRAINT [DF_t_caishu_c3] DEFAULT ((0)),
[c4] [int] NOT NULL CONSTRAINT [DF_t_caishu_c4] DEFAULT ((0)),
[c5] [int] NOT NULL CONSTRAINT [DF_t_caishu_c5] DEFAULT ((0)),
[c6] [int] NOT NULL CONSTRAINT [DF_t_caishu_c6] DEFAULT ((0)),
[c7] [int] NOT NULL CONSTRAINT [DF_t_caishu_c7] DEFAULT ((0)),
[c8] [int] NOT NULL CONSTRAINT [DF_t_caishu_c8] DEFAULT ((0)),
[c9] [int] NOT NULL CONSTRAINT [DF_t_caishu_c9] DEFAULT ((0))
) ON [PRIMARY]
go
insert into [t_caishu](c1,c3,c4,c8)values(3,5,6,8)
insert into [t_caishu](c3,c7)values(8,6)
insert into [t_caishu](c2,c6,c8)values(7,1,5)
insert into [t_caishu](c1,c2,c5)values(9,6,2)
insert into [t_caishu](c4,c6)values(9,5)
insert into [t_caishu](c5,c8,c9)values(4,3,9)
insert into [t_caishu](c2,c4,c8)values(4,5,7)
insert into [t_caishu](c3,c7)values(7,2)
insert into [t_caishu](c2,c6,c7,c9)values(1,7,3,4)
go
select * from [t_caishu]
就这样一个9行9列的表,
最后我要得到一个2列的表,数据为
'c21','2,9'
'c51','1,7,9'
...
'c12','1,2,4,5,7'
...