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)
 Get customers who modified last 'X hours

Author  Topic 

getur.srikanth@gmail.com
Yak Posting Veteran

77 Posts

Posted - 2008-01-15 : 12:25:51
I need a query that need to get all customers those who modified their details in last 'X' hours.

fields are customerid, firstname, lastname, datecreated,datemodified.

Thanks in advance

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-01-15 : 12:34:50
declare @hours int
set @hours = 1

select * from YourTable
where datemodified >= dateadd(hh, -1*@hours, getdate())

"...database development, while a serious pursuit and vitally important to business, should be fun!"
-Adam Machanic
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-15 : 12:37:17
SELECT customerid, firstname, lastname, datecreated,datemodified FROM TABLE WHERE datemodified > DATEADD(hh,@x,GETDATE())

@x will be negative number giving last x hour
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 01:37:52
For better clarity, I use

where datemodified >= dateadd(hour, -1*@hours, getdate())


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-16 : 01:42:33
quote:
Originally posted by madhivanan

For better clarity, I use

where datemodified >= dateadd(hour, -1*@hours, getdate())


Madhivanan

Failing to plan is Planning to fail


Yeah.This is much better approach madhi.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-16 : 10:33:14
Due to laziness, i often use
where datemodified >= dateadd(hour, -@hours, getdate())





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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-17 : 00:26:13
quote:
Originally posted by khtan

Due to laziness, i often use
where datemodified >= dateadd(hour, -@hours, getdate())





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




Then you must have used

where datemodified >= dateadd(hh, -@hours, getdate())

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-17 : 00:28:25
quote:
Originally posted by madhivanan

quote:
Originally posted by khtan

Due to laziness, i often use
where datemodified >= dateadd(hour, -@hours, getdate())





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




Then you must have used

where datemodified >= dateadd(hh, -@hours, getdate())

Madhivanan

Failing to plan is Planning to fail



Nope. for clarity i use hour


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-17 : 01:18:11
<<
Nope. for clarity i use hour
>>

Clarity-cum-Laziness

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -