April 2, 2021 at 12:22 pm
How do I preserve the value (and not result to 0).
In the below calculation, how do I preserve the value? I want atleast 0.01 to come out instead of 0.
declare @q int
declare @weight decimal(33,13)
set @q = 6
set @weight = 0.0000000060240
select Sum(@q *COALESCE(NULLIF(COALESCE(@Weight, 0), 0), 0.01))
Result = 0.0000000
April 2, 2021 at 12:42 pm
Did you try
select convert(decimal(22,2), Case when Sum(@q *COALESCE(NULLIF(COALESCE(@Weight, 0), 0), 0.01)) < 0.01 then 0.01
else Sum(@q *COALESCE(NULLIF(COALESCE(@Weight, 0), 0), 0.01))
end )
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
April 2, 2021 at 1:37 pm
This will explain why SQL is returning only 6 decimal places. If you change @weight to this declare @weight decimal(15,13), ten it will return the value
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply