解决方案 »

  1.   

    本帖最后由 DBA_Huangzj 于 2014-05-05 13:17:03 编辑
      

  2.   

    你能解释一下这个函数在mysql中是干嘛的吗?
      

  3.   

    这个是以前mysql项目中的函数,现在要换成sqlserver数据库,这个函数执行不了!具体功能由于刚接触项目,也不熟悉
      

  4.   

    大概看了一下,看上去想这个函数的功能,你执行一下试试 
    if not object_id('Tab') is null
        drop table Tab
    Go
    Create table Tab([Col1] int,[Col2] nvarchar(1))
    Insert Tab
    select 1,N'a' union all
    select 1,N'b' union all
    select 1,N'c' union all
    select 2,N'd' union all
    select 2,N'e' union all
    select 3,N'f'
    Go
     
    合并表:
     
    SQL2000用函数:
     
    go
    if object_id('F_Str') is not null
        drop function F_Str
    go
    create function F_Str(@Col1 int)
    returns nvarchar(100)
    as
    begin
        declare @S nvarchar(100)
        select @S=isnull(@S+',','')+Col2 from Tab where Col1=@Col1
        return @S
    end
    go
    Select distinct Col1,Col2=dbo.F_Str(Col1) from Tab
     
    go