Solved

Transact-SQL Loses decimals on divide

Posted on 2004-08-08
2
1,156 Views
Last Modified: 2008-03-10
Hello,

Why, does 15 / 60 return 0?  For example, in transact-sql, if I execute the query

print 15 / 60

SQL returns 0 instead of 0.25.

I guess it is assuming an Integer datatype for some reason.... how could I fix that?

Thanks!
0
Comment
Question by:quiTech
[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
2 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 11749514
You need to make the numerator a decimal:

DECLARE @num1 decimal(10,5)
SET @num1 = 15
SELECT @num1 / 60
0
 

Author Comment

by:quiTech
ID: 11749567
Works great!  Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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