Possible Duplicate:
Concatenate many rows into a single text string?
I have a query
SELECT city FROM cityTable
it returns
delhi
faridabad
haryana
mathura
kerla
I just want result in transpose manner something like
delhi | faridabad | haryana | mathura | kera
How is it possible?
SELECT STUFF (
(SELECT N', ' + city FROM CityTable FOR XML PATH(''),TYPE)
.value('text()[1]','nvarchar(max)'),1,2,N'')
Concatenate many rows into a single text string?
declare @city nvarchar(max)
SELECT @city = coalesce(@city+' | ', '')+city FROM cityTable
EDIT:
In order to show the result
SELECT @city
You can use the PIVOT
and UNPIVOT
as the example posted on here
TSQL – Transpose Data using Using PIVOT and UNPIVOT
NOTE: You can find the syntax on BOL (books on line) of SQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With