go if OBJECT_ID('test')is not null drop table test go create table test( value int ) insert test select 1 union all select 2 union all select 3 union all select 4 union all select 5 declare @str varchar(20) set @str='' select @str=@str+','+ltrim(value) from test select RIGHT(@str,LEN(@str)-1) as value/* value 1,2,3,4,5 */
谢谢,找到方法了 Select STUFF((Select ','+RoleName FROM tbRole WHERE ID IN (SELECT RoleID FROM tbAdminRole WHERE AdminID = 9) FOR XML PATH('')),1,1,''); 主要是想实现在网页上显示的管理员列表里,显示出每个管理员所属的多个角色,上面的整个语句还需要作为一个子查询放在管理员查询语句里
go
if OBJECT_ID('test')is not null
drop table test
go
create table test(
value int
)
insert test
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 declare @str varchar(20)
set @str=''
select @str=@str+','+ltrim(value) from test
select RIGHT(@str,LEN(@str)-1) as value/*
value
1,2,3,4,5
*/
Select STUFF((Select ','+RoleName FROM tbRole WHERE ID IN (SELECT RoleID FROM tbAdminRole WHERE AdminID = 9) FOR XML PATH('')),1,1,'');
主要是想实现在网页上显示的管理员列表里,显示出每个管理员所属的多个角色,上面的整个语句还需要作为一个子查询放在管理员查询语句里