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
 General SQL Server Forums
 New to SQL Server Programming
 date comparision

Author  Topic 

learntsql

524 Posts

Posted - 2009-10-13 : 01:24:40
How to comapre the date columns and datetime variable/getdate() value in where clause which are differing by seconds there by query doesnt return any rows.
how to canvert both the values.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-13 : 01:27:33
Your question is not clear. Please post your query.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

learntsql

524 Posts

Posted - 2009-10-13 : 01:50:15
my requirement is as follows

declare @dateVal datetime
declare @init int
set @dateVal=getdate()
set @init=1 --represents the how many days old data required
select * from TabHistory
where CreatedOn=dateadd(dd,@init*-1,@dateVal)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-13 : 02:19:00
the following query will gives you CreateOn @init days ago

where CreatedOn >= dateadd(day datediff(day, 0, getdate()), -@init)
and CreatedOn < dateadd(day datediff(day, 0, getdate()), -@init + 1)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -