Solved

Why does SQLCMD doesn't return values returned by query?

Posted on 2011-09-14
8
841 Views
Last Modified: 2012-05-12
I have a query that returns the price of a bunch of products.
The prices contain 4 decimals but I want 2 decimals so I use ROUND.

select
ROUND (items.articleprice,2) as Price
from items

The query works but when I use SQLCMD to run the query it still returns 4 decimals instead of 2.

How can I make SQLCMD to return just 2 decimals?
0
Comment
Question by:Clyde_Radcliffe
8 Comments
 
LVL 6

Expert Comment

by:yjchong514
ID: 36536999
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 36541078
or round the value that you are getting as result from sqlcmd.
0
 

Author Comment

by:Clyde_Radcliffe
ID: 36541253
@yjchong514 and TempDBA,

The query is already in and .sql file.
And the uery already contains round.
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 36541315
wow. Then I will recommend rechecking the code again.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Clyde_Radcliffe
ID: 36541627
@TempDBA

There isn't much code involved.
The actual value of the articleprice is 12.98999

When I enter the queryselect ROUND (items.articleprice,2) as Price from items manually it returns the value 12.99 wich is correct.

When I place the same query in an .sql file and run it with cmdsql it returns the value 12.98999 wich is incorrect.
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 36541762
What I meant while writing using round in the above comment was : Instead of using round function in the current place, use it at the time you are displaying.

Anyway, will post if any other idea is clicked.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 36548445
please use CAST, eventually on TOP of ROUND.

select CAST(items.articleprice AS DECIMAL(20,2)) as Price from items

Open in new window

0
 

Author Closing Comment

by:Clyde_Radcliffe
ID: 36567668
Works like a charm!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

13 Experts available now in Live!

Get 1:1 Help Now