declare @t table(col int)
insert @t select 1
union all select 2
union all select 3
declare @s varchar(100)
set @s=''
select @s=@s+' '+cast(col as varchar) from @t
select @s
你看看这个 还有 在邹建出的那本书上有合并行的额
insert @t select 1
union all select 2
union all select 3
declare @s varchar(100)
set @s=''
select @s=@s+' '+cast(col as varchar) from @t
select @s
你看看这个 还有 在邹建出的那本书上有合并行的额
ordercode varchar(2),
productcode varchar(20),
slipcode varchar(20),
updatetime datetime
)
Insert into temptbl
select 'AA','7841001111301','585072','2005-12-22 00:00:00.000'
union select 'AA','7841001121027','585072','2005-12-22 00:00:00.000'
union select 'CA','7841001121027','585072','2005-12-22 00:00:00.000'
union select 'AA','7841001121034','585072','2005-12-22 00:00:00.000'
union select 'CA','7841001121034','585072','2005-12-22 00:00:00.000'
union select 'FA','7841001121034','585072','2005-12-22 00:00:00.000'
go
create FUNCTION uf_HBdata(@pcode varchar(20),@Scode varchar(20),@updatetime Datetime)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @r varchar(8000)
SET @r=''
SELECT @r=@r+' '+rtrim(ordercode)
FROM temptbl
WHERE productcode=@pcode and slipcode=@Scode and updatetime=@updatetime
RETURN(substring(@r,2,8000))
END
go
SELECT ordercode=dbo.uf_HBdata(productcode,slipcode,updatetime) ,
productcode,slipcode,updatetime
FROM temptbl
GROUP BY productcode,slipcode,updatetime
go
用函数嵌套在SQL命令语句里面实现!
Text 字段,将合并后字符串每次 8K以内一次次 Update Text吧。我很久没有操作过 Text 字段了,如何 update Text 字段我忘了。我试验了一下,基本可以满足你的要求
declare @t text
set @t = replicate('abc',3000)
create table t ( t1 text)
insert into t ( t1 ) values (replicate('abc',3000))
-------------------------
http://chinadba.cn
深圳骄子数据库服务网
最具实战经验的数据库优化,管理,设计,培训