日期:2014-05-17 浏览次数:20516 次
create table Test (barcode varchar(20),aa varchar(100))
go
insert into test
values('6900000000007','0.00(2),')
go
insert into test
values('6900000000007','8.00(2),')
go
insert into test
values('6900000000083','95.00(1),')
go
insert into test
values('6900000000083','86.20(1),')
go
select barcode,
aa=stuff((select ''+aa from test where barcode=a.barcode for xml path('')),1,1,'')
from test a group by barcode
/*
barcode aa
-------------------- -----------------
6900000000007 0.00(2),8.00(2),
6900000000083 5.00(1),86.20(1),
create table Test (barcode varchar(20),aa varchar(100))
go
insert into test
values('6900000000007','0.00(2),')
go
insert into test
values('6900000000007','8.00(2),')
go
insert into test
values('6900000000083','95.00(1),')
go
insert into test
values('6900000000083','86.20(1),')
go
create function getstr(@id varchar(20))
returns varchar(100)
as
begin
declare @str varchar(100)
set @str=''
select @str=@str+aa from Test where barcode=@id
return @str
end
select barcode,dbo.getstr(barcode) from test group by barcode
/*
barcode
--------------------&