Solved

SQL Query doing division

Posted on 2014-11-10
2
152 Views
Last Modified: 2014-11-10
When i run this query it returns a 0.  Why?

Select 10 / 42
0
Comment
Question by:vbnetcoder
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40433766
Because SQL Server treats this as 'integer math', meaning an integer divided by an integer should return an integer value.   Sounds kinda hokey I know.

To return the decimal portion of this expression, either change one of the numbers to include decimal places, or cast one of the values to a decimal data type.
SELECT 10 / 42.0
-- or
SELECT 10 / CAST(42 as numeric(19,4))

Open in new window

0
 

Author Closing Comment

by:vbnetcoder
ID: 40433792
Thank you!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql help 8 55
SSRS Subscription jobs disabled, yet still running 4 35
Oracle - Query link database loop 8 39
Syntax for query to update table 2 13
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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