Solved

Transact-SQL Loses decimals on divide

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

685 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