Hi Everyone,
I am trying to write a stored proceedure, that will return records (from
2 Tables) where the last updated date was within the last hour.
Here is my query so far:
Select a.ID, UserName, JoinDate, LastAction as LastActivity, Title
From dbo.Access a
Join UserActions ua
on a.ID = ua.ID
Join News n
on a.Username = n.Poster
Where ua.LastAction < DateDiff(hour,GetDATE()-1, GETDATE())
If anyone could help, that would be great.
ThanksHello,
Try the below query:-
Select LastAction as LastActivity, Title
From dbo.Access a
Join UserActions ua
on a.ID = ua.ID
Join News n
on a.Username = n.Poster
Where Datediff(hh,getdate(),ua.LastAction)<=1
Thanks
Hari
"Mick Walker" <Mick.Walker@.privacy.net> wrote in message
news:5cg5qlF30ifdqU1@.mid.individual.net...
> Hi Everyone,
> I am trying to write a stored proceedure, that will return records (from 2
> Tables) where the last updated date was within the last hour.
> Here is my query so far:
> Select a.ID, UserName, JoinDate, LastAction as LastActivity, Title
> From dbo.Access a
> Join UserActions ua
> on a.ID = ua.ID
> Join News n
> on a.Username = n.Poster
> Where ua.LastAction < DateDiff(hour,GetDATE()-1, GETDATE())
> If anyone could help, that would be great.
> Thanks|||On 3 Jun, 16:42, Mick Walker <Mick.Wal...@.privacy.net> wrote:
> Hi Everyone,
> I am trying to write a stored proceedure, that will return records (from
> 2 Tables) where the last updated date was within the last hour.
> Here is my query so far:
> Select a.ID, UserName, JoinDate, LastAction as LastActivity, Title
> From dbo.Access a
> Join UserActions ua
> on a.ID = ua.ID
> Join News n
> on a.Username = n.Poster
> Where ua.LastAction < DateDiff(hour,GetDATE()-1, GETDATE())
> If anyone could help, that would be great.
> Thanks
...
WHERE ua.LastAction > DATEADD(HOUR,-1,CURRENT_TIMESTAMP);
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment