Advertisement

10.12.2007 at 03:05AM PDT, ID: 22889167
[x]
Attachment Details

Divison of integers (integer division)

Asked by deusex in SQL Server 2005

Tags: division, integer, sql

A quote from http://classicasp.aspfaq.com/general/why-does-4/5-0.html:

"Why does 4 / 5 = 0?
SQL Server
 
You may be startled to see the result of this calculation in SQL Server:
 SELECT 4 / 5
 -----------  
0
 (1 row(s) affected)
 This is because SQL Server is performing integer division... which ignores decimals / fractions / remainders. There are a couple of ways you can force the behavior you really want:
 SELECT 4.0 / 5
 SELECT 4 * 1.0 / 5
 SELECT CAST(4 AS DECIMAL(5,1)) / 5"

There are many JET (MS Access) queries I should translate to T-SQL. I'd like to avoid those 3 ways.
Is there some sql server 2005 setting I should set to force the division to be a floating point division instead of an integer division when both denominator & numerator are integers ?
Start Free Trial
[+][-]10.12.2007 at 03:22AM PDT, ID: 20064149

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2007 at 03:46AM PDT, ID: 20064232

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2007 at 03:50AM PDT, ID: 20064249

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: division, integer, sql
Sign Up Now!
Solution Provided By: asvforce
Participating Experts: 5
Solution Grade: B
 
 
[+][-]10.12.2007 at 04:05AM PDT, ID: 20064307

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2007 at 05:09AM PDT, ID: 20064573

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628