declare @s varchar(200) set @s='''a'',''b'',''c'',''d'''select @s='select '+replace(@s,',',' union select ') print @s
select 'a' union select 'b' union select 'c' union select 'd'
谢谢 bill024(咖啡熊) !接分!~
还有一点问题,我想把它做成返回个table的函数,但sql不允许这样: create function fn_getTableByString( @STR as varchar(200) ) returns table as begin select @s='select '+replace(@s,',',' union select ') exec (@s) end该怎杨解决呢?
set @s='''a'',''b'',''c'',''d'''select @s='select '+replace(@s,',',' union select ')
print @s
create function fn_getTableByString(
@STR as varchar(200)
)
returns table as
begin
select @s='select '+replace(@s,',',' union select ')
exec (@s)
end该怎杨解决呢?