?
Solved

Query to show records that are less than 30 days out of sysdate

Posted on 2005-04-21
2
Medium Priority
?
370 Views
Last Modified: 2010-03-19
I have this query which will show me records where the UHCXDATE is 30 days away from the sysdate.  How can I adjust the query so that it will include records 30 days or more but less than 60, thanks

SELECT distinct  c1.accountno,
                  c1.company,
                  c1.title,
                  c1.phone1,
                  c1.key1 as [EEs],
                  c1.address1,
                  c1.address2,
                  c1.city,
                  c1.state,
                  c1.zip,
                  c1.key3 as [Territiory BDM],
                  c1.key5 as [Client or Suspect]
                  FROM contact1 c1 JOIN contact2 c2 ON c1.accountno = c2.accountno
                  WHERE c2.UHCXDATE = convert(datetime,convert(char(10),getdate(),101))+30 order by company asc
0
Comment
Question by:ratzephyr
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 13833558
Hi ratzephyr,

You might be better off using the DateDiff function :

Select
...
Where
DateDiff(day,c2.UHCXDATE,getdate()) >= 30 And DateDiff(day,c2.UHCXDATE,getdate()) <60
Order by .....

Tim Cottee
0
 
LVL 1

Expert Comment

by:Mannaraprayil
ID: 13833651
SELECT distinct  c1.accountno,
               c1.company,
               c1.title,
               c1.phone1,
               c1.key1 as [EEs],
               c1.address1,
               c1.address2,
               c1.city,
               c1.state,
               c1.zip,
               c1.key3 as [Territiory BDM],
               c1.key5 as [Client or Suspect]
               FROM contact1 c1 JOIN contact2 c2 ON c1.accountno = c2.accountno
               WHERE c2.UHCXDATE BETWEEN DATEADD(DAY,30,getdate()) AND  DATEADD   (DAY,60,getdate()) order by company asc

Hope this will help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

839 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