question

mitche0027 avatar image
mitche0027 asked

Computed column in SELECT CASE t-sql

I've got a computed column: BilledAmount = CASE WHEN CoverageItem in ('MED','RNB', 'LAB') THEN ISNULL(SUM(ISNULL(hb.BilledAmt,0)),0) END FROM HospitalBill hb with(nolock) Basically, what it does is sum up the amount billed with a coverage item of for example MED from the HospitalBill table...What I wan't to do is to add another case which if the CoverageItem = 'BEN'... then the BilledAmount would be the sum of the BilledAmounts with the CoverageItem of 'LAB' and 'BEN'.. is that possible..
sql-server-2008tsql
10 |1200

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

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
Sure, you can do that. Just add another WHEN and THEN clause before the END statement and you should be fine.
10 |1200

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

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.