Solved

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

Posted on 2011-09-14
8
890 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
[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
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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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