Monday, March 26, 2012

Microsoft Query?

I am using Microsoft Query to query against an SQL database and place the data into a pivot table but cannot figure out how to get the preceding 4 days worth of data. I currently am trying to get this to work using the following;

>=#3/13/2007# And <=#3/13/2007 11:59:59 PM#...this works, but i would like this so the report will run without hard coding dates.. i am trying to use this but with no luck.

>=getdate() And <=dateadd(dd,-1,getdate())

any ideas?

I think you need to reverse your logic to the following:

WHERE @.MyDate <= getdate() AND @.MyDate >= dateadd(dd,-1,getdate())

or equally :

WHERE @.MyDate BETWEEN dateadd(dd,-1,getdate()) AND getdate()

The criteria that you specified are impossible to meet.

Chris

No comments:

Post a Comment