SELECT name ,
( SUM(CASE WHEN TransTypeName LIKE 'credit%' THEN amount
ELSE 0
END) - SUM(CASE WHEN TransTypeName LIKE 'Debit%' THEN amount
ELSE 0
END) ) * 5 / 100 AS Interest
FROM .....
This query return some negative value,I want convert negative value into zero. How to write a query
Something like this maybe?
SELECT t1.name AS Name, CASE WHEN t1.Interest > 0 THEN Interest ELSE 0 END AS Interest
FROM (select name, (sum(case when TransTypeName like 'credit%' then amount else 0 end) - sum(case when TransTypeName like 'Debit%' then amount else 0 end)) *5/100 as Interest from ...........) as t1
Just give this
select greatest(:yourval,0)
(Works in Azure and SQL Server 2022.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With