在SQL语句(或过程)中,我想将此表的行折叠为单个逗号分隔的字符串.
simpleTable
id value
-- -----
1 "a"
2 "b"
3 "c"
Run Code Online (Sandbox Code Playgroud)
折叠为:
"a, b, c"
Run Code Online (Sandbox Code Playgroud) 考虑以下tsql ...
create function dbo.wtfunc(@s varchar(50)) returns varchar(10) begin return left(@s, 2); end
GO
select t.* into #test from (
select 'blah' as s union
select 'foo' union
select 'bar'
) t
select * from #test;
declare @s varchar(100);
set @s = '';
select @s = @s + s from #test order by s;
select @s;
set @s = '';
select @s = @s + s from #test order by dbo.wtfunc(s);
select @s;
/* 2005 only*/
select cast((select s+'' from …Run Code Online (Sandbox Code Playgroud)