Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help with SQL date calculations

Posted on 2006-03-30
6
Medium Priority
?
273 Views
Last Modified: 2008-02-01
I am using the shazam report wizard to generate a report to give me a list of chemicals that are expired.

Here is what I have so far.

SELECT MAIN.NameRaw,
         LOCATES.Location,
         MAIN.NameSorted,
         BATCH.UniqueContainerID,
         MAIN.ID,
         MAIN.CASNo,
         MAIN.StructuralFormula,
         MAIN.IsSupplyItem,
         BATCH.Quantity,
         SIZETYPE.Size_Description,
         BATCH.Expiration
    FROM ":cisdata:MAIN.DB" MAIN,
         ":cisdata:BATCH.DB" BATCH,
         ":cisdata:LOCATES.DB" LOCATES,
         ":cisdata:SIZETYPE.DB" SIZETYPE
   WHERE ((MAIN.ID = BATCH.ID)
     AND (BATCH.SizeTypeID = SIZETYPE.SizeTypeID)
     AND (BATCH.LocationID = LOCATES.LocationID))
     AND (((BATCH.Expiration < "03/30/2006")))
ORDER BY MAIN.NameRaw ASC,
         LOCATES.Location ASC,
         MAIN.NameSorted ASC

The date "03/30/2006" is actually shown in the defined search as <TODAY.  I guess it just gives the "calculated value" when I actually look at the SQL code.

How could I modify the code to give me anything that expires within 30 days?  I tried <TODAY + 30 but that returns and error.

0
Comment
Question by:browneye9000
6 Comments
 

Expert Comment

by:raviberi
ID: 16339600
Use GETDATE()+30
0
 
LVL 17

Accepted Solution

by:
HuyBD earned 1000 total points
ID: 16340293
Try this!

DATEADD (day, 30, GETDATE())

It return new date(today+30days)
0
 

Author Comment

by:browneye9000
ID: 16342919
Neither of these worked.  Shazam report wizard can be difficult from what I understand.  I get a type mismatch error for either of these.

After entering in the QBE, this is what it writes at the SQL.

SELECT MAIN.NameRaw,
         LOCATES.Location,
         MAIN.NameSorted,
         BATCH.UniqueContainerID,
         MAIN.ID,
         MAIN.CASNo,
         MAIN.StructuralFormula,
         MAIN.IsSupplyItem,
         BATCH.Quantity,
         SIZETYPE.Size_Description,
         BATCH.Expiration
    FROM ":cisdata:MAIN.DB" MAIN,
         ":cisdata:BATCH.DB" BATCH,
         ":cisdata:LOCATES.DB" LOCATES,
         ":cisdata:SIZETYPE.DB" SIZETYPE
   WHERE ((MAIN.ID = BATCH.ID)
     AND (BATCH.SizeTypeID = SIZETYPE.SizeTypeID)
     AND (BATCH.LocationID = LOCATES.LocationID))
     AND (((BATCH.Expiration < "DATEADD (day, 30, GETDATE()) ")))
ORDER BY MAIN.NameRaw ASC,
         LOCATES.Location ASC,
         MAIN.NameSorted ASC

It did the same type of thing with the first one.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16344128
this:

AND (((BATCH.Expiration < "DATEADD (day, 30, GETDATE()) ")))
ORDER BY MAIN.NameRaw ASC,
         LOCATES.Location ASC,
         MAIN.NameSorted ASC


should be :

AND (((BATCH.Expiration < DATEADD (day, 30, GETDATE()) )))
ORDER BY MAIN.NameRaw ASC,
         LOCATES.Location ASC,
         MAIN.NameSorted ASC

no " s in the expression

AW
0
 

Author Comment

by:browneye9000
ID: 16344425
I removed the "s and I get the error.

Invalid use of keyword.  Token day,. Line Number: 19.

I wonder if the report wizard can handle this kind of code.  BTW it is used to qry a paradox db.
0
 

Author Comment

by:browneye9000
ID: 16350095
I decided to use access to report.  Thanks for the help though.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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