create function getstr(@a int,@b int,@c int)
returns varchar(2000)
as 
begin
declare @str varchar(2000)
set @str=''
select @str=@str+','+cast(d as varchar(10)) from table表 where a=@a and b=@b and c=@c
set @str=right(@str,len(@str)-1)
return @str
end
go
select a,b,c,dbo.getstr(a,b,c) d into 一新表  from table表 group by a,b,c

解决方案 »

  1.   

    你试试看大力的那个function呢
      

  2.   

    create function getstr(@a int,@b int,@c int)
    returns varchar(2000)
    as 
    begin
    declare @str varchar(2000)
    set @str=''
    select @str=@str+','+cast(d as varchar(10)) from table表 where a=@a and b=@b and c=@c
    set @str=@a+','+@b+','+@c+','+right(@str,len(@str)-1)
    return @str
    end
    goselect dbo.getstr(a,b,c) d,identity(int,1,1) Newid into #临时表 from table表 group by a,b,c
    TRY:declare @I
    set @I=1
    while @I<=(select max(newID) from #临时表)
    begin
    exec('insert into 你的表
      select '+select d from #临时表 where newid=@i)
     set @i=@i+1
    end
      

  3.   

    CrazyFor(蚂蚁) 的意思是对的,但是执行的时候有这个错误:"服务器: 消息 245,级别 16,状态 1,过程 gets,行 8
    将 varchar 值 ',' 转换为数据类型为 int 的列时发生语法错误。"麻烦你再帮我看看.