Groups | Blog | Home
all groups > sql server programming > april 2006 >

sql server programming : Help: select DATEDIFF(day,date1,getDate())/DATEDIFF(day,date1,date2) as r_ratio from test;


zxo102
4/15/2006 8:42:22 PM
Hi everyone,
I need your help. I have a simple query against the table: test in
SQL server
select DATEDIFF(day,date1,getDate())/DATEDIFF(day,date1,date2) as
r_ratio from test;
where date1 and date2 are the two fields (datetime). Also date2 >
getDate() > date1.

This query returns 0 since all decimals are truncated. But I do need
the decimal ratio. Anybody knows how to get it? Thanks.

Ouyang
zxo102
4/15/2006 11:50:41 PM
Steve,

Both ways work. That is what I want. Thank you very much.

Ouyang
Steve Kass
4/15/2006 11:59:19 PM
Try

1.00*DATEDIFF(day,date1,getDate())/DATEDIFF(day,date1,date2)
or

CAST(
DATEDIFF(day,date1,getDate())
AS DECIMAL(10,1))/DATEDIFF(day,date1,date2)

Different precision/scale will give different numbers
of significant digits.

Steve Kass
Drew University


[quoted text, click to view]
AddThis Social Bookmark Button