1

I am reading an excel file using sql

select ISNULL(F4,'RCS(mean)') AS WEB1_CD,cast(round(F5,2) as numeric(36,1)) 
   AS Value,ISNULL(F9,'RCS(mean)') AS WEB_MD,F10 AS Value from 
     OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 
       Xml;Database=D:\_TPRCS\SampleFileForStudy.xlsx;HDR=YES','select * FROM 
         [0537259$B22:K28]') WHERE F5 IS NOT NULL

and the result is

enter image description here

Now I want to make my rows as columns so I can get my variables value. I want result as in below image

enter image description here

Rizwan Ali Sabir
  • 468
  • 1
  • 7
  • 18

1 Answers1

0

I did it by using SQL PIVOT

SELECT [RCS(mean)] ,[STDEV], [Min],[Max]
FROM (SELECT ISNULL(F4,''RCS(mean)'') as val ,F5 FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'', ''Excel 12.0 Xml;Database=D:\_TPRCS\SampleFileForStudy.xlsx;HDR=YES'',''select * FROM [Sheet1$f24:k28]'') ) up
PIVOT (MAX(F5) FOR val IN ([RCS(mean)],[STDEV], [Min],[Max])) AS pvt
Rizwan Ali Sabir
  • 468
  • 1
  • 7
  • 18