Solved

Sybase query - handling negative numbers

Posted on 2013-06-14
1
604 Views
Last Modified: 2013-06-17
We have a program that is needs to amounts into character strings for output, but it needs to handle negative numbers and does not.
This is the current piece of the SQL query being ran  “PAID_AMOUNT = convert(char(11),PAID_AMOUNT), “


How might we show the output with a negative number?

Looking for the SQL:
0
Comment
Question by:garyinmiami2003
1 Comment
 
LVL 13

Accepted Solution

by:
alpmoon earned 500 total points
ID: 39249313
You can use str function instead of convert:

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks101.htm

str

Description:
Returns the character equivalent of the specified number.

Syntax:
str(approx_numeric [, length [, decimal] ])

Parameters

approx_numeric

    is any approximate numeric (float, real, or double precision) column name, variable, or constant expression.

length

    sets the number of characters to be returned (including the decimal point, all digits to the right and left of the decimal point, and blanks). The default is 10.

decimal

    sets the number of decimal digits to be returned. The default is 0.

Example:

select str(-12345, 6)
------
-12345
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…

828 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