Tpaul_10
asked on
Need a query
Experts,
Need a query to get the results anything <= 90 days of the purchasedate from my values below.
=============
PurchaseDate
=============
2011-12-12
2011-01-01
2011-07-05
2011-07-03
2011-05-01
2013-01-01
2012-01-01
I am trying the following but it's not showing 2011-12-12 ,2013-01-01 ,2012-01-01 in my results set.
select * From mydb..mytable datediff(day,getDate(),pur
Thanks in adance.
None of those are less than 90 days
Date datediff(day,getDate(),pur chasedate)
2011-12-12 217
2012-01-01 237
2013-01-01 603
Date datediff(day,getDate(),pur
2011-12-12 217
2012-01-01 237
2013-01-01 603
I'm not sure what you mean either....
I'll take a stab at it and guess you meant: "I want to find all purchases made within the last 90 days".
WHERE purchasedate >= #ninetyDaysAgo#
AND purchasedate < #dateTomorrow#
ie ...
WHERE purchasedate >= <cfqueryparam value="#dateAdd('d', -90, now())#" cfsqltype="cf_sql_date">
AND purchasedate < <cfqueryparam value="#dateAdd('d', 1, now())#" cfsqltype="cf_sql_date">
If that's not what you mean, what are the desired results in plain english?
I'll take a stab at it and guess you meant: "I want to find all purchases made within the last 90 days".
WHERE purchasedate >= #ninetyDaysAgo#
AND purchasedate < #dateTomorrow#
ie ...
WHERE purchasedate >= <cfqueryparam value="#dateAdd('d', -90, now())#" cfsqltype="cf_sql_date">
AND purchasedate < <cfqueryparam value="#dateAdd('d', 1, now())#" cfsqltype="cf_sql_date">
If that's not what you mean, what are the desired results in plain english?
you want the returned recordset to be within 90 days of today ?
WHERE " . getdate(now()) . " BETWEEN purchasedate-90 AND purchasedate
i'm not sure of the exact syntax, but the logic should work.
WHERE " . getdate(now()) . " BETWEEN purchasedate-90 AND purchasedate
i'm not sure of the exact syntax, but the logic should work.
if not, then . . .
WHERE purchasedate BETWEEN " . getdate(now()) . " AND " . getdate(now()+90)
WHERE purchasedate BETWEEN " . getdate(now()) . " AND " . getdate(now()+90)
>> WHERE purchasedate BETWEEN " . getdate(now()) . " AND " . getdate(now()+90) <<
Is that valid sql server syntax?
Is that valid sql server syntax?
ASKER
I am sorry for not to be clear.
If I run the query today, I shouldn't get the dates that are older than 90 days, but should get any future dates
=============
PurchaseDate
=============
2011-12-12
2011-01-01
2010-07-05
2011-07-03
2011-05-01
2013-01-01
2012-01-01
So, my outout from the above data should be
=============
PurchaseDate
=============
2011-12-12
2011-07-03
2011-05-01
2013-01-01
2012-01-01
Thanks and hope that helps. I am going to try the Agx and DarkMain suggestions
If I run the query today, I shouldn't get the dates that are older than 90 days, but should get any future dates
=============
PurchaseDate
=============
2011-12-12
2011-01-01
2010-07-05
2011-07-03
2011-05-01
2013-01-01
2012-01-01
So, my outout from the above data should be
=============
PurchaseDate
=============
2011-12-12
2011-07-03
2011-05-01
2013-01-01
2012-01-01
Thanks and hope that helps. I am going to try the Agx and DarkMain suggestions
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you mean "anything <=90 days of the purchase date"