?
Solved

return 2 digits from sql statement with a divide in it

Posted on 2007-10-03
4
Medium Priority
?
845 Views
Last Modified: 2008-01-09
Sql statment:
select Sum((ialrtartot-ialrtvptot)/(ialrtartot)) as Yield from table.

I only want 2 digits returned for yield, i.e. .26.

Thanks
0
Comment
Question by:bergertime
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
cmhunty earned 2000 total points
ID: 20007186
Does this work?

select CAST(Sum((ialrtartot-ialrtvptot)/(ialrtartot)) AS decimal(10,2)) as Yield from table
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20007297
select ROUND(Sum((ialrtartot-ialrtvptot)/(ialrtartot)),2) as Yield from table
0
 
LVL 2

Author Comment

by:bergertime
ID: 20007607
cmhunty, it works but rounds down, sql server dba it rounds up but does not cut off the digits, as I get .29000000.  Since it does not have to be rounded up it will work for me,  thanks to both of you.
0
 
LVL 11

Expert Comment

by:cmhunty
ID: 20007718
Guess you could do both!

select CAST(ROUND(Sum((ialrtartot-ialrtvptot)/(ialrtartot)),2) AS decimal(10,2)) as Yield from table
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

840 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