January 26, 2010 at 9:56 am
I've been doing SQL for a very long time. I have a vendor report that uses the -isnull(sum(somefield), 0). I know what the isnull() does, but I've never seen it preceded with a minus sign before. The statement does not return an error. Has anyone ever seen this before?
January 26, 2010 at 10:02 am
Can you post the rest of the statement?
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
January 26, 2010 at 10:05 am
select isnull(sum(u.quantity),0) as q, -isnull(sum(u.linecost),0) as d
from matusetrans u
where u.issuetype in ('ISSUE','RETURN')
and u.transdate< 200912
January 26, 2010 at 10:11 am
It looks like -isnull(sum(u.linecost),0) means -1 * isnull(sum(u.linecost),0)
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
January 26, 2010 at 10:15 am
At first, I thought maybe that would be what it was, but the results of the query return a positive value for column d
January 26, 2010 at 10:52 am
May be the sum is giving a negetive value and they wanted to show absolute(positive value). Have a look at this,
SELECT -isnull(1, 0)
SELECT -isnull(-1, 0)
---------------------------------------------------------------------------------
January 26, 2010 at 11:12 am
You could be correct. But why not use the ABS() function. It would be clear and sort of self-documenting. We are going to ask the vendor to document the report and I guess we'll find out then why they did this.
Thanks for all of the answers.
January 26, 2010 at 11:23 am
cathy.baker (1/26/2010)
You could be correct. But why not use the ABS() function. It would be clear and sort of self-documenting. We are going to ask the vendor to document the report and I guess we'll find out then why they did this.Thanks for all of the answers.
Hang on here. -1 * sum is NOT the same as ABS(). I'm guessing whoever wrote that statement wanted -1 * the sum, and was NOT trying to remove the - sign.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
January 26, 2010 at 11:28 am
If I remove the - sign, I get a positive value, with it I get a negative value. But further down there is another similar query that does the exact opposite. So, I am assuming that it is doing -1 * value. Thanks again to everyone. This has definitely been interesting.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply