Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need a query

Posted on 2011-05-09
9
Medium Priority
?
237 Views
Last Modified: 2012-05-11

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(),purchasedate) <= (90)

Thanks in adance.
0
Comment
Question by:Tpaul_10
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 35722894
Huh?  Because those are more than 90 days in the future????

What do you mean "anything <=90 days of the purchase date"
0
 
LVL 53

Expert Comment

by:_agx_
ID: 35722914
None of those are less than 90 days

Date                 datediff(day,getDate(),purchasedate)
2011-12-12      217
2012-01-01      237
2013-01-01      603
0
 
LVL 53

Expert Comment

by:_agx_
ID: 35723022
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?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Expert Comment

by:DarkMain
ID: 35726651
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.
0
 

Expert Comment

by:DarkMain
ID: 35726667
if not, then . . .

     WHERE purchasedate BETWEEN " . getdate(now()) . " AND " . getdate(now()+90)
0
 
LVL 53

Expert Comment

by:_agx_
ID: 35730677
>> WHERE purchasedate BETWEEN " . getdate(now()) . " AND " . getdate(now()+90) <<

Is that valid sql server syntax?
0
 

Author Comment

by:Tpaul_10
ID: 35733859
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

0
 
LVL 53

Accepted Solution

by:
_agx_ earned 400 total points
ID: 35733890
>> I shouldn't get the dates that are older than 90 days
>> but should get any future dates

I was guessing you wanted within the last 90 days (not future dates).  If you want future dates too, try:

WHERE  purchasedate >= <cfqueryparam value="#dateAdd('d', -90, now())#" cfsqltype="cf_sql_date">

ie  If today is May 10, 2011, it becomes
WHERE purchasedate  >=  '2011-02-09'  
0
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 400 total points
ID: 35735508
select * From mydb..mytable datediff(day,purchasedate,getDate()) <= (90)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question