colums to single row
-
Hi All, table ----- NAme Age Total ---- --- ------ Ram 26 800 kumar 36 300 Sam 34 200 output should be ------ Name:Ram Age:26 Total:800 ;Name:Kumar Age:36 Total:300;Name..... Please help me with this .tried using COALESCE but I could not achieve..
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
-
Hi All, table ----- NAme Age Total ---- --- ------ Ram 26 800 kumar 36 300 Sam 34 200 output should be ------ Name:Ram Age:26 Total:800 ;Name:Kumar Age:36 Total:300;Name..... Please help me with this .tried using COALESCE but I could not achieve..
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
You can do it like this...
DECLARE @String VARCHAR(8000)
set @String = ''SELECT @String = @String + 'Name:' + ISNULL(Name,'NULL') + ' Age:' + Age + ' Total:' + Total + '; '
FROM TABLEprint @String
Silence is golden... but duct tape is silver!! Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!
-
Hi All, table ----- NAme Age Total ---- --- ------ Ram 26 800 kumar 36 300 Sam 34 200 output should be ------ Name:Ram Age:26 Total:800 ;Name:Kumar Age:36 Total:300;Name..... Please help me with this .tried using COALESCE but I could not achieve..
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
-
Hi All, table ----- NAme Age Total ---- --- ------ Ram 26 800 kumar 36 300 Sam 34 200 output should be ------ Name:Ram Age:26 Total:800 ;Name:Kumar Age:36 Total:300;Name..... Please help me with this .tried using COALESCE but I could not achieve..
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
Hi.... Try This....
DECLARE @Temp TABLE(Name VARCHAR(20),Age TINYINT, Total INT)
INSERT INTO @Temp(Name,Age,Total)
SELECT 'Ram',26,800
UNION ALL
SELECT 'kumar',36,300
UNION ALL
SELECT 'Sam',34,200DECLARE @SQLStr VARCHAR(8000)
SET @SQLStr = ''SELECT @SQLStr = @SQLStr + 'Name:' + Name + ' Age:' + CAST(Age AS VARCHAR) + ' Total:' + CAST(Total AS VARCHAR) + '; '
FROM @TempPRINT @SQLStr