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 2005 Forums
 Transact-SQL (2005)
 Select Results based on Latest date

Author  Topic 

Bananadon
Starting Member

3 Posts

Posted - 2009-01-27 : 04:48:47
I have a table call rates with the following columns.
rateID int
Rate decimal
DateEffective DateTime

I want to select the correct date based of the effective date

I have tried
SELECT * FROM Rates WHERE 01/12/2008 > DateEffective

But this doesn't work

Any Suggestions?

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-27 : 04:54:08
SELECT * FROM Rates WHERE DateEffective < = '01/12/2008'
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-27 : 04:55:34
select * from callrates where dateadd(dd,datediff(dd,0,DateEffective ),0) < dateadd(dd,datediff(dd,0,getdate()),0)
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-27 : 05:01:03
select * from callrates where dateeffective < (select max(dateeffective) from callrates)

Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 09:23:59
did you meant this?

SELECT * FROM Rates WHERE DateEffective>=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
AND DateEffective<DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
Go to Top of Page
   

- Advertisement -