May 20, 2013 at 1:50 am
All,
I want to display -0 when i run the below query
select 0.0*-1
karthik
May 20, 2013 at 2:44 am
Getting -0 as result after performing some numeric operation is not possible
We will have to do some string concatenation to achieve this result
Can you give a bit more details as to what you are trying to do using tables, variables, etc.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
May 20, 2013 at 4:01 am
pls find the attached documents.
karthik
May 20, 2013 at 4:22 am
You will need CASE statement and some hard-coding to achieve this result
SELECTCASE WHEN SUM(trans_amt) BETWEEN -0.99 AND 0 THEN '-0.00' ELSE CAST( SUM(trans_amt) AS VARCHAR(30)) END
FROMacc_bal_may
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
May 20, 2013 at 4:49 am
Are you producing the report?
This one is one of the most stupid requirements I ever seen.
Zero, as a numeric thing, cannot be negative. Some times it used for showing temperature in weather to show that it's just low enough for water to freeze.
As soon as you add - to 0 it's stop to be numeric and starts to be a formatted string.
I would only do it in UI (eg. reporting tool).
If this is used for some sort of data extract, it's still will way better to show it in two separate columns. One is numeric value (0) and another one, CHAR(1), sign.
Than you can pass whatever you like.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply