Showing posts with label PIVOT. Show all posts
Showing posts with label PIVOT. Show all posts

Wednesday, July 30, 2014

PIVOT Table in MS SQL

Table Structure


Now Pivot those  Tables like this

WITH AllowedAmount AS (
   SELECT
CAST(round(MAP.AllowedAmt,2) AS NUMERIC(36,2)) AllowedAmt
    ,c.CPT
    ,CAST(round(c.Charges,2) AS NUMERIC(36,2)) Charges
    , F.NAME
   FROM
      dbo.POSEVAllowedAmtMap MAP
      FULL JOIN POSEVAllowedAmtConfig c ON c.ID =MAP.AllowedAmtId
   LEFT OUTER JOIN dbo.finclass F
      ON MAP.FinClassId = F.FinClass_Id
   
)
SELECT *
FROM
   AllowedAmount
   PIVOT (Max(AllowedAmt) FOR NAME
    IN (Aetna,
Blue,
Cigna,
Humana,
Medicaid,
Medicare,
Tricare,
United,
Other,
CMS)) P    


Check Result of PIVOT Query Result