Solved

convert positive to negative in SQL

Posted on 2014-12-19
4
119 Views
Last Modified: 2014-12-21
How can I convert below number to positive number?

-2650.000000
0
Comment
Question by:VBdotnet2005
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 250 total points
ID: 40510266
ABS (-2650.000000)
0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 250 total points
ID: 40510282
The question head mentioned to negative, but its text mentioned positive.

Try: for a number i,
SELECT -(i);

Specific example: -(-2650.000000)
0
 
LVL 37

Assisted Solution

by:Neil Russell
Neil Russell earned 125 total points
ID: 40510538
Or of course multiply by -1 IF you know its always negative.  But if you only ever want a positive and dont know if it will be positive or negative to start with then use hnasr's example of ABS(number).
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 125 total points
ID: 40510935
I'm not sure of what it is you're trying to do, but these commands (some already suggested) will generate the following results:
Multiply by -1 ==> will convert negative to positive and positive to negative
Use ABS() function ==> will always return positive (i.e. converts negative to positive and leaves positive as positive)
Multiply ABS() function by - 1 ==> will always return negative
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question