USE AdventureWorks
GO
-- Check Table Column
SELECT Name
FROM HumanResources.Shift
GO
-- Get CSV values
SELECT SUBSTRING(
(SELECT ',' + s.Name
FROM HumanResources.Shift s
ORDER BY s.Name
FOR XML PATH('')),2,200000) AS CSV
GORisultati:Name -------------------------------------------------- Day Evening Night CSV -------------------------------------------------- Day,Evening,Night
Altro metodo:
DECLARE @a AS VARCHAR(4000) SET @a = '' SELECT @a = @a + Nome + ',' FROM Argomenti_tb SELECT @aRisultati:
--------------------------------------------------------------------------------- Notizie,Primo Piano,Galleria Fotografica,Argomento pubblico 1,Aromento Privato 1,
Altro metodo: COALESCE
DECLARE @fruitNames VARCHAR(8000) SELECT @fruitNames = COALESCE(@fruitNames + ', ', '') + FruitName FROM Fruits SELECT FruitNames = @fruitNamesRisultati:
FruitNames ‐‐‐‐‐‐‐‐‐‐ Apple, Orange, Mango, Banana, GrapeThe COALESCE function is used to ensure that there is no comma (,) after the last FruitName.
trovati qui.