Custom Search
Logiclabz
  • Home
  • Sql Server
  • Changes Row to Columns (Transpose) in Sql Server 2005 using COALESCE

Changes Row to Columns (Transpose) in Sql Server 2005 using COALESCE

Sample table as Cities in rows is convert to single column

State (Tablename)
-----
City (Columnname)
-----
Chennai
Madurai
Coimbatore
declare @retstr varchar(8000)
 select Top 5 @retstr =  COALESCE(@retstr + ';','') + City 
from State
print @retstr
Result:
Chennai;Madurai;Coimbatore


Comments

  • yogesh says:
    May 01, 09

    Please check this link to Transpose Columns to Rows in Sql Server 2005

  • bill says:
    Dec 11, 09

    I log SSIS package execution but want to transform the table into a xtab to allow calculation of stats. I have data like process event eventDt dayEvent timeEvent eoo start 2009-08-16 03:30:08.843 08/16/2009 03:30:08:843 eoo stop 2009-08-16 03:37:42.887 08/16/2009 03:37:42:887 eoo start 2009-08-18 03:30:12.907 08/18/2009 03:30:12:907 eoo stop 2009-08-18 03:57:55.090 08/18/2009 03:57:55:090 eoo start 2009-08-20 03:30:12.533 08/20/2009 03:30:12:533 eoo stop 2009-08-20 03:53:22.613 08/20/2009 03:53:22:613 but want it as process start stop eoo 2009-08-16 03:30:08.843 2009-08-16 03:37:42.887 Any suggestions?

  • kakasaheb says:
    Jul 16, 10

    Chivtya


Leave a reply


Do you like this post?