question

spelleje avatar image
spelleje asked

Question with writing a function that will add the total of different types

Hello I was wondering how I would be able to write a function that would add the sum of the COST_AMT of a certain group with the same COST_TYP_CD. I pretty much want every transaction that falls under a COST_TYP_CD of FINE to not be added to the rest. There are different RECEIPT_ID's and want them to be displayed as separate. So I pretty much want every RECEIPT_ID to have two COST_AMT displayed, one under FINE and CC (all the other COST_TYP_CD that is not FINE) Thank you!

sql server 2014
capture1.png (15.6 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·

Do you mean something like this?

SELECT Receipt_ID, 
SUM(CASE WHEN COST_TYPE_CD <> 'FINE' THEN CALC ELSE 0 END) AS NotFine,
SUM(CASE WHEN COST_TYPE_CD = 'FINE' THEN CALC ELSE 0 END) AS Fine
FROM Receipts
GROUP BY Receipt_ID
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.