Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Refresh Data from Current Date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

36 Posts

Posted - 09/08/2009 :  12:00:59  Show Profile  Reply with Quote
I have multiple queries which auto refresh some data. I need the query to always run for the current date.

Can someone advise how I go about achieving?

Here is a sample of my query.

SELECT slhist.DATE, slhist.OPERATOR, slhist.QTY, slhist.PRICE, slhist.DISC1
FROM dbo.slhist slhist
WHERE (slhist.DATE={d '2009-09-07'}) AND (slhist.OPERATOR='0005')

Many thanks

Flowing Fount of Yak Knowledge

2875 Posts

Posted - 09/08/2009 :  12:18:29  Show Profile  Reply with Quote
This is how you would do it in MS SQL
WHERE slhist.Date = dateadd(day,datediff(day,0,getdate()),0)


Everyday I learn something that somebody else already knew
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 09/09/2009 :  02:27:50  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
More accurately

slhist.Date >= dateadd(day,datediff(day,0,getdate()),0) and
slhist.Date < dateadd(day,datediff(day,0,getdate()),1)


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

Starting Member

36 Posts

Posted - 09/09/2009 :  04:27:55  Show Profile  Reply with Quote

I probably wasn't being very clear but this query is running in MS Query in Excel - have inserted the code as below. MS Query does not throw an error but when I run the query no data is returned. Any ideas?

SELECT slhist.ACCOUNT, slhist.DATE
FROM dbo.slhist slhist
WHERE (slhist.DATE>=dateadd(day,datediff(day,0,getdate()),0) And slhist.DATE<dateadd(day,datediff(day,0,getdate()),1))
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000