日期:2014-05-18 浏览次数:20767 次
--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([id] int,[name] varchar(6),[Pid] int) insert [test] select 1,'通信',0 union all select 2,'通信_1',1 union all select 3,'通信_2',1 union all select 4,'通信_3',1 union all select 5,'汽车',0 union all select 6,'汽车_1',5 union all select 7,'移动',0 union all select 8,'移动_1',7 declare @str varchar(100) set @str='' select @str=@str+','+[name] from test where id in(1,2,4,7,8) select right(@str,len(@str)-1) as value /* value --------------------------------------- 通信,通信_1,通信_3,移动,移动_1 */