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
 Refresh Data from Current Date

Author  Topic 

dibblejon
Starting Member

36 Posts

Posted - 2009-09-08 : 12:00:59
Hi
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

jimf
Master Smack Fu Yak Hacker

2875 Posts

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

Jim

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-09 : 02:27:50
More accurately

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



Madhivanan

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

dibblejon
Starting Member

36 Posts

Posted - 2009-09-09 : 04:27:55
Thanks

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
   

- Advertisement -