Solved

sql query

Posted on 2013-11-24
3
253 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

733 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