Solved

Transact-SQL Loses decimals on divide

Posted on 2004-08-08
2
1,150 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
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now