Solved

sql query

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query Help - MSSQL - Averages 5 27
Can > be used for a Text field 6 49
SQL view 2 27
average of calculation (TSQL) 4 9
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

821 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