here you go with the full illustration--your sample table with the datadeclare @t table(Act int,ActNumber int,[SR1_Male_Less than 20 years] int,[SR1_Male_Less than 30 years] int,[SR1_Male_Less than 40 years] int,[SR2_Enroll_Pat] int,[SR2_Enroll_Pat1] int,[SR2_Enroll_Pat2] int)insert @tvalues(1, 201, 2, 2, 4, 5, 4, 5)--YOUR ACTUAL SOLUTIONselect Act,ActNumber,LEFT(cat,CHARINDEX('_',cat+'_')-1) AS [Table],REVERSE(LEFT(REVERSE(cat),CHARINDEX('_',REVERSE(cat)+'_')-1)) AS [Row],CASE WHEN cat LIKE '%Male%' THEN value END AS male,CASE WHEN cat LIKE '%Enroll%' THEN value END AS Enrollfrom @tunpivot (value for cat in ([SR1_Male_Less than 20 years] ,[SR1_Male_Less than 30 years] ,[SR1_Male_Less than 40 years] ,[SR2_Enroll_Pat] ,[SR2_Enroll_Pat1] ,[SR2_Enroll_Pat2]))uoutput---------------------------------------------------------------------------Act ActNumber Table Row male Enroll---------------------------------------------------------------------------1 201 SR1 Less than 20 years 2 NULL1 201 SR1 Less than 30 years 2 NULL1 201 SR1 Less than 40 years 4 NULL1 201 SR2 Pat NULL 51 201 SR2 Pat1 NULL 41 201 SR2 Pat2 NULL 5
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs