• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

add debit to case statement

select *,
case resultcode
when 'Canceled' then 'Payment Processed'
when 'Completed' then 'Payment Processed'
when 'confirmed' then 'Payment Processed'
when 'Denied' then 'Payment Processed'
when 'Pending' then 'Payment Processed'
when 'unconfirmed' then 'Payment Processed'
when '' then 'Payment Processed'
when 'Reversed' then 'Refunded'
end as resultcodetype

,debit - convert(money, paymentfee) as 'NetAmount' from payments where isnumeric(paymentfee) = 1



this query works, but I want to add another condition to resultcodetype
when resultcode='' and (debit>=0 or debit has no value) then 'Payment Processed'
when resultcode='' and debit<0 then 'Refunded'
0
rgb192
Asked:
rgb192
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Ephraim WangoyaCommented:

select *,
case
when resultcode = 'Canceled' then 'Payment Processed'
when resultcode = 'Completed' then 'Payment Processed'
when resultcode = 'confirmed' then 'Payment Processed'
when resultcode = 'Denied' then 'Payment Processed'
when resultcode = 'Pending' then 'Payment Processed'
when resultcode = 'unconfirmed' then 'Payment Processed'
when (resultcode = '' and (debit>=0 or debit is null)) then 'Payment Processed'
when (resultcode = '' and (debit < 0)) then 'Refunded'
when resultcode = '' then 'Payment Processed'
when resultcode = 'Reversed' then 'Refunded'
end as resultcodetype
0
 
wdosanjosCommented:
I think you almost provided the answer unless I'm missing something:

select *,
case resultcode
when 'Canceled' then 'Payment Processed'
when 'Completed' then 'Payment Processed'
when 'confirmed' then 'Payment Processed'
when 'Denied' then 'Payment Processed'
when 'Pending' then 'Payment Processed'
when 'unconfirmed' then 'Payment Processed'
when '' and (debit>=0 or debit is null) then 'Payment Processed'
when '' and debit<0 then 'Refunded'
--when '' then 'Payment Processed'   -- I think this no longer makes sense. Please verify.
when 'Reversed' then 'Refunded'
end as resultcodetype

,debit - convert(money, paymentfee) as 'NetAmount' from payments where isnumeric(paymentfee) = 1
0
 
wdosanjosCommented:
Oops. @ewangoya got it first.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ragnarok89Commented:
I believe

case
   when debit >= 0 or debit = 'null'
     then 'Payment Processed
   when debit <= 0
     then 'Refunded'

is what you need
0
 
rgb192Author Commented:
debit may be null or debit may be '' or debit may be a alphanumeric value

if this is the case, then I want resultcodetype to be 'Payment Processed'
0
 
Ephraim WangoyaCommented:

use ISNUMERIC to check whether debit is numeric or not

when ((resultcode = '') and  ((Debit is null) or (Debit = '') or (not ISNUMERIC(Debit)) ) then
0
 
wdosanjosCommented:
Please try:

select *,
case
when resultcode = 'Canceled' then 'Payment Processed'
when resultcode = 'Completed' then 'Payment Processed'
when resultcode = 'confirmed' then 'Payment Processed'
when resultcode = 'Denied' then 'Payment Processed'
when resultcode = 'Pending' then 'Payment Processed'
when resultcode = 'unconfirmed' then 'Payment Processed'
when resultcode = '' and (debit is null or ISNUMERIC(debit) = 0 or cast(debit as money) >=0) then 'Payment Processed'
when resultcode = '' and debit is not null and ISNUMERIC(debit) = 1 and CAST(debit as money)<0 then 'Refunded'
--when resultcode = '' then 'Payment Processed'   -- I think this no longer makes sense. Please verify.
when resultcode = 'Reversed' then 'Refunded'
end as resultcodetype

,debit - convert(money, paymentfee) as 'NetAmount' from payments where isnumeric(paymentfee) = 1
0
 
rgb192Author Commented:
best answer thansk
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now