1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| CREATE FUNCTION [dbo].[Concat] (@Code nvarchar(10))
RETURNS nvarchar(20) AS
BEGIN
DECLARE @TexteConcat nvarchar(20)
SET @TexteConcat = ''
SELECT @TexteConcat = @TexteConcat + Class + ';'
FROM Table1
WHERE Code=@Code
ORDER BY Class
RETURN @TexteConcat
END
SELECT distinct Code, dbo.Concat(Code)
from (
select distinct Code, Class
from table1 T1
,table2 T2
where T1.Code=T2.Code
and Code in ('0200349546','0200349553','0200349561')
and T2.GroupingCode='01'
) as aa
order by Code |
Partager