Solved

sql query

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

691 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