iscomar001
7/15/2015 - 10:01 PM

Concatenate select

Concatenate select

DECLARE @message varchar(1000) 
DECLARE @saltoLinea VARCHAR(100)
SET @saltoLinea = CHAR(13) + CHAR(10);

WITH tblTest(descripcion,id)as(
	SELECT ' DESC1',1 UNION ALL
	SELECT ' DESC2',2 UNION ALL
	SELECT ' DESC3',3  
)
SELECT @message = 
	ISNULL(@message,'') + 
	CASE 
		WHEN @message IS NULL THEN '' 
		ELSE  @saltoLinea 
	END + 
	descripcion + ' ' + CAST( id  as varchar(100))
FROM tblTest

print @message


DECLARE @Names VARCHAR(8000) 
SELECT @Names = COALESCE(@Names + ', ', '') + 
    ISNULL(Name, 'N/A')
FROM People