Martin James

Martin James

  • NA
  • 100
  • 15.5k

UNPIVOT with NULL values

Mar 31 2021 2:51 PM
I have the following query : 
  1. SELECT Custid, Shipperid, Freight  
  2. FROM Sales.FreightTotals  
  3. UNPIVOT( Freight FOR Shipperid IN([1],[2],[3]) ) AS U;  
I have the following result :
 
custid    shipperid    freight
1              1              98
1              3              55
2              2              75
 
This is my expected output :
 
custid    shipperid    freight
1              1              98
1              2              NULL
1              3              55
2              1              NULL
2              2              75
2              3              NULL

Answers (1)