日期:2014-05-17 浏览次数:20802 次
if object_id('test') is not null drop table test
go
create table test(项目 nvarchar(10),金额 float)
go
insert into test
select N'学费', 20 union all
select N'杂费', 30 union all
select N'书费', 2.5
go
select 项目+convert(varchar(5),金额)+';' from test for xml path('')
/*
XML_F52E2B61-18A1-11d1-B105-00805F49916B
----------------------------------------------------------------------------------------------------------------
学费20;杂费30;书费2.5;
*/
------解决方案--------------------
declare @T table (项目 varchar(4),金额 varchar(4))
insert into @T
select '学费','20' union all
select '杂费','30' union all
select '书费','2.5'
declare @sql varchar(8000)
select @sql=isnull(@sql+',','')+项目+金额 from @t
select @sql as [合并]
/*
合并
-----------------------
学费20,杂费30,书费2.5
*/