谢谢楼上的 ,能不能说的具体些。
我是想生成一张象这样的表:select 'a'
union
select 'b'
union
select 'c'
union
select 'd'

解决方案 »

  1.   

    declare @s varchar(200)
    set @s='''a'',''b'',''c'',''d'''select @s='select '+replace(@s,',',' union select ')
    print @s
      

  2.   

    select 'a' union select 'b' union select 'c' union select 'd'
      

  3.   

    谢谢 bill024(咖啡熊) !接分!~
      

  4.   

    还有一点问题,我想把它做成返回个table的函数,但sql不允许这样:
    create function fn_getTableByString(
    @STR as varchar(200)
    )
    returns table as
    begin
    select @s='select '+replace(@s,',',' union select ')
    exec (@s)
    end该怎杨解决呢?