先使用一个函数
Create Function getName(@ID int)
returns nvarchar(50)
as
begin
declare @temp nvarchar(10)
set @temp = ''
select @temp = @temp + 用户信息 from 用户表 where 用户ID = @ID
return substring(@temp,2,len(@temp))
endselect distinct 用户ID, dbo.getName(用户ID) as '用户信息' from 用户表
Create Function getName(@ID int)
returns nvarchar(50)
as
begin
declare @temp nvarchar(10)
set @temp = ''
select @temp = @temp + 用户信息 from 用户表 where 用户ID = @ID
return substring(@temp,2,len(@temp))
endselect distinct 用户ID, dbo.getName(用户ID) as '用户信息' from 用户表
把表里的数据先倒入到其中一个字符串二维数组里a1,进行分类编程,用for循环
内嵌if 进行a1[n][0]分类 连接a1[n][1]连接,接的时候不要忘了逗号,只要有国家计算机二级C的编程功底,不应该是难事,再把处理的结果放到a2[m][2],再导入原来的表里
CREATE FUNCTION dbo.Test ()
RETURNS @table table
(
ida int,
iname nvarchar(30)
)
AS
BEGIN
declare @temp nvarchar(30),@ID int
set @temp=''
declare cr cursor
for select distinct 用户ID from 用户表
open cr
fetch next from cr into @ID
while @@fetch_status=0
begin
select @temp=@temp+用户信息 from 用户表 where 用户ID=@ID
insert into @table(ida,iname) values(@ID,@temp)
end
return
END
CREATE FUNCTION dbo.Test ()
RETURNS @table table
(
ida int,
iname nvarchar(30)
)
AS
BEGIN
declare @temp nvarchar(30),@ID int
set @temp=''
declare cr cursor
for select distinct 用户ID from 用户表
open cr
fetch next from cr into @ID
while @@fetch_status=0
begin
select @temp=@temp+','+用户信息 from 用户表 where 用户ID=@ID
insert into @table(ida,iname) values(@ID,substring(@temp,2,len(@temp)))
end
return
END