Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Divide returning 0

Author  Topic 

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-04-11 : 17:22:14
Why would this be returning 0? If I take out / 942084 it returns the correct number.

DECLARE @y date
DECLARE @d date

SET @y = DATEADD(m, -12, CURRENT_TIMESTAMP)
SET @d = CAST(GETDATE() AS date)

SELECT (COUNT(*) * 200000) / 942084
FROM tbl_HAW_HealthAndSafety_LRI
WHERE Convert(date, EventDate) BETWEEN @y AND @d

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-04-11 : 17:31:04
quote:
Originally posted by chapm4

Why would this be returning 0? If I take out / 942084 it returns the correct number.

DECLARE @y date
DECLARE @d date

SET @y = DATEADD(m, -12, CURRENT_TIMESTAMP)
SET @d = CAST(GETDATE() AS date)

SELECT (COUNT(*) * 200000) / 942084.0
FROM tbl_HAW_HealthAndSafety_LRI
WHERE Convert(date, EventDate) BETWEEN @y AND @d




This behavior is explained here
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-12 : 00:44:48
http://beyondrelational.com/modules/2/blogs/70/posts/10825/beware-of-implicit-conversions.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

chapm4
Yak Posting Veteran

58 Posts

Posted - 2012-04-12 : 09:15:00
Thanks for the answer and explanation.
Go to Top of Page
   

- Advertisement -