Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql query

Posted on 2013-11-24
3
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 600 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 150 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

618 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