Solved

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

Posted on 2011-09-14
8
870 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
Independent Software Vendors: 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!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GeoClustering  and AOG 25 43
sql2016-WIn10: standard,for SQL servc-account.. 51 44
SQL Rewrite without the NULLIF 4 25
compare date to getdate() 8 18
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Detach & Attach 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 Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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