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 2000 Forums
 SQL Server Development (2000)
 Can this be done by a subquery?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-11 : 09:22:17
Allen Weiss writes "Hi,
Below you will see a select statement that works fine using SQL2000 db:

Select Title, folder, hitcalc,link, dateyear, hits,(hits/DATEDIFF(d, dateyear, getdate()+1)) as hot from archives order by (hits/DATEDIFF(d, dateyear, getdate()+1)) desc

However, notice that if DATEDIFF is 0 I get an error message (obviously from dividing by 0). What I would like to know is whether I can write this statement some other way (perhaps using a subquery) to first eliminate any records for which DATEDIFF=0 and then run the above select statement - thereby eliminating any records that will cause this problem.

In general I asking a broader question, that is whether you can, in 1 sql statement, first eliminate certain records based on a criteria, and then select the rest where (and this is important) you are making a calculation at the same time - as I am with my "hot" variable.

Any help on this would be deeply appreciated. Thanks."
   

- Advertisement -