mardi 4 mars 2014

Turning certain rows into columns in SQL Server


Vote count:

0




Please see table below:



For each CustomerID + PaymentID + ClaimNum, there are 3 NULL values for the ItemID & Qty.


I want to take these 3 NULL values and put them as COLUMNS.


DeductionID 1085 = Service Fee (Column Name)


DeductionID 486 = Freight Charge (Column Name)


DeductionID 559 = Handling Charge (Column Name)


For example, let's take the ClaimNum for the highlighted NULLs:


Doing what I want to do, it would end up with the following columns:


CustomerID, PaymentID, ClaimNum, ItemID, Qty, Amount, Service Fee, Freight Charge, Handling Charge


I'm not sure if I need to do a CROSS JOIN, PIVOT or UNPIVOT here. I've never done this in the past and reading Microsoft's website on this isn't really helping. Can anyone give me a hand?


Let me know if you need more info. I appreciate all the help!!



asked 46 secs ago

Rj.

804





Aucun commentaire:

Enregistrer un commentaire