Copy codeThe Code is as follows:
Create table tb (standards varchar (50), amount varchar (50), variation varchar (50), statuss varchar (50), Reason varchar (50 ))
Insert into tb values ('55', '123456', '4', 'backlog of things ', 'Insufficient processing staff and equipment; slow T-sorting ;')
Insert into tb values ('55', '000000', '4', 'overstocked things ', 'Insufficient parts ;')
Insert into tb values ('55', '000000', '4', 'amount backlog ', 'cross-site backlog; many drawing problems ;')
Insert into tb values ('56 ', '123456', '4', 'item backlog', 'aaaa ;')
Insert into tb values ('56 ', '000000', '4', 'overstocked things', 'bbbb ;')
Insert into tb values ('56 ', '123456', '4', 'item backlog', '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
Call
Copy codeThe Code is as follows:
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