Solved

sql query

Posted on 2013-11-24
3
248 Views
Last Modified: 2013-11-26
Query:

update #temp
SET [Invoice $ Delta]=[Invoice $ to date]-[Sales Order $ to date]

[Invoice $ Delta] : If the value is negative it must be displayed in brackets
[Invoice $ Delta] :  column must have the thousand separator

Please suggest how to modify above update statement as per the above requirement.

existing data types of [Invoice $ Delta], [Invoice $ to date], [Sales Order $ to date] is DECIMAL(18,2)
0
Comment
Question by:sqldba2013
3 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 200 total points
ID: 39672812
you wouldn't normally store the data in the way you're suggesting you want it displayed...

that is usually considered the responsibility of the calling process to arrange...

if you want to display the output as you specified

then try

select case when [Invoice $ Delta] <0 then '(' else '' end+convert(varchar(30),[Invoice $ Delta])+case when [Invoice $ Delta]<0 then ')' else '' end
from #temp
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 50 total points
ID: 39672820
That is not a query issue, but rather a formatting issue.

On the SELECT query it would be:

SELECT FORMAT ( [Invoice $ Delta], money, 'en-us' )  as  [Invoice $$ Delta]
FROM #temp

Open in new window


SQL handles numbers, generally, as either an integer data type or decimal values.

Now if you do any math involving an integer and decimal data type it will give you an integer type back.
0
 

Author Closing Comment

by:sqldba2013
ID: 39676932
--
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now