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
 Help with a stored procedure

Author  Topic 

BBassic
Starting Member

10 Posts

Posted - 2012-05-10 : 04:26:00
Hi there,

I'm trying to put together a stored procedure which pulls a list of orders placed on the current day but I can't figure it out.

It needs to show all orders placed prior to executing the query but only for the current day. So if I used it at 2pm it'd need to show all orders placed between midnight and 2pm

Can anyone point me in the right direction?

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-10 : 04:37:11
quote:
It needs to show all orders placed prior to executing the query but only for the current day

SQL Server will not know when did you last execute that stored procedure. Unless in your stored procedure, you stored the last execution date and time somewhere everytime it is executed


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

Go to Top of Page

BBassic
Starting Member

10 Posts

Posted - 2012-05-10 : 04:39:43
quote:
Originally posted by khtan

quote:
It needs to show all orders placed prior to executing the query but only for the current day

SQL Server will not know when did you last execute that stored procedure. Unless in your stored procedure, you stored the last execution date and time somewhere everytime it is executed


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





Thanks for that. My brain is saying that I could do something using the BETWEEN clause along with GETDATE but it isn't helping me out any further than that
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-05-10 : 08:10:08
where datecol>=dateadd(day,datediff(day,0,getdate()),0) and datecol<getdate()

Find more examples here
http://beyondrelational.com/modules/2/blogs/70/posts/10899/understanding-datetime-column-part-iii.aspx

Madhivanan

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

- Advertisement -