Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Display -0 Expand / Collapse
Author
Message
Posted Monday, May 20, 2013 1:50 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
All,

I want to display -0 when i run the below query

select 0.0*-1


karthik
Post #1454423
Posted Monday, May 20, 2013 2:44 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 2,631, Visits: 4,723
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.



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1454439
Posted Monday, May 20, 2013 4:01 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
pls find the attached documents.

karthik

  Post Attachments 
Book1.xlsx (5 views, 11.27 KB)
req.txt (10 views, 2.04 KB)
Post #1454465
Posted Monday, May 20, 2013 4:22 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 2,631, Visits: 4,723
You will need CASE statement and some hard-coding to achieve this result

SELECT	CASE WHEN SUM(trans_amt) BETWEEN -0.99 AND 0 THEN '-0.00' ELSE CAST( SUM(trans_amt) AS VARCHAR(30)) END
FROM acc_bal_may




Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1454472
Posted Monday, May 20, 2013 4:49 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, August 18, 2014 8:36 AM
Points: 2,836, Visits: 5,066
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.


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1454480
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse