Solved

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

Posted on 2011-09-14
8
862 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 25

Expert Comment

by:TempDBA
ID: 36541315
wow. Then I will recommend rechecking the code again.
0
 

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 143

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

'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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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