SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

dibblejon
Starting Member

36 Posts

Posted - 09/08/2009 :  12:00:59  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2869 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)

Jim

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

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 09/09/2009 :  02:27:50  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 - 09/09/2009 :  04:27:55  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New 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.11 seconds. Powered By: Snitz Forums 2000