Archive

Archive for April, 2017

Use of PIVOT in SQL

April 18, 2017 Leave a comment

SELECT * FROM (SELECT

CASE

WHEN ProductCode=’SH’ THEN ‘SH’

WHEN ProductCode =’SF’ AND InvestmentAccountID =-1 THEN ‘CFDINdex’

ELSE ‘SF’ END AS ProductCode

FROM Positions WHERE Id= <any Value>

)

AS data

PIVOT

(

COUNT(ProductCode)

FOR ProductCode IN(SH, SF) –Name of column that you want to your output column wise

) AS pvt

 

Categories: SQL