复制代码 代码如下:
CREATE TABLE tb(standards varchar(50), amount varchar(50), variation varchar(50),statuss varchar(50),Reason varchar(50))
insert into tb values('55','279','4','物量积压','加工人员设备不足;T排制作进度较慢;')
insert into tb values('55','279','4','物量积压','部件人员不足;')
insert into tb values('55','279','4','物量积压','跨间场地积压;图纸问题较多;')
insert into tb values('56','300','4','物量积压','AAAA;')
insert into tb values('56','300','4','物量积压','BBBB;')
insert into tb values('56','300','4','物量积压','CCCC;')
create function test(@standards varchar(100))
returns varchar(8000)
as
begin
declare @re varchar(500)
set @re = ''
select @re = @re+','+Reason
from tb
where @standards=standards
return (stuff(@re,1,1,''))
end
调用
复制代码 代码如下:
select distinct standards,amount,variation,statuss,Reason = dbo.test('55') from tb where standards=55
select distinct standards,amount,variation,statuss,Reason = dbo.test('56') from tb where standards=56
CREATE TABLE tb(standards varchar(50), amount varchar(50), variation varchar(50),statuss varchar(50),Reason varchar(50))
insert into tb values('55','279','4','物量积压','加工人员设备不足;T排制作进度较慢;')
insert into tb values('55','279','4','物量积压','部件人员不足;')
insert into tb values('55','279','4','物量积压','跨间场地积压;图纸问题较多;')
insert into tb values('56','300','4','物量积压','AAAA;')
insert into tb values('56','300','4','物量积压','BBBB;')
insert into tb values('56','300','4','物量积压','CCCC;')
create function test(@standards varchar(100))
returns varchar(8000)
as
begin
declare @re varchar(500)
set @re = ''
select @re = @re+','+Reason
from tb
where @standards=standards
return (stuff(@re,1,1,''))
end
调用
复制代码 代码如下:
select distinct standards,amount,variation,statuss,Reason = dbo.test('55') from tb where standards=55
select distinct standards,amount,variation,statuss,Reason = dbo.test('56') from tb where standards=56
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/shujuku/MsSQL/99837.html