Results 1 to 2 of 2

Thread: query for items from last 30 days

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586

    query for items from last 30 days

    Greetings,

    I wanted to add the clause "records from the last 30 days only" to the query below. And say PROT_COM_HEADER.SYSTEM_TIME rerprsented the date field. How would I say it?

    The query presently is set up to:

    1) Get the top 3000 records from the table in descending order (soas to get the last 3000 records very quickly, as opposed to having to scan through the first 57,000 records), and then

    2) sort the records ascendingly (soas to have the last 3000 records displayed in ascending order).

    Now, its amatter of filtering through those last 3000 ascending records for the alst 30 days. He doesn't want to have to change the date in the query every day. I'm thinking there would likely be a way to say "the computer's system time minus 30 days"; anid i'm just wondering if anyone here might know how i would say that and apply it to my query below.


    SELECT
    PROT_COM_HEADER.SYSTEM_TIME,
    PROT_COM_HEADER.Machine,
    PROT_COM_HEADER.RunOutErrorPinion,
    PROT_COM_HEADER.RunOutErrorGear,
    PROT_COM_HEADER.BestPos_Deviat_J,
    PROT_COM_HEADER.[Description],
    PROT_SFT_STD_Orders_Mesh_REF.REF_DMESH,
    PROT_SFT_STD_Orders_Mesh_REF.REF_CMESH
    FROM
    PROT_COM_HEADER, PROT_SFT_STD_Orders_Mesh_REF
    WHERE
    PROT_COM_HEADER.SYSTEM_TIME = PROT_SFT_STD_Orders_Mesh_REF.SYSTEM_TIME
    AND PROT_COM_HEADER.SYSTEM_TIME IN
    (
    SELECT TOP 3000 SYSTEM_TIME
    FROM
    PROT_COM_HEADER
    ORDER BY SYSTEM_TIME DESC
    )
    ORDER BY PROT_COM_HEADER.SYSTEM_TIME ASC

    Thanks!
    Jim

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Asuming msSQL
    VB Code:
    1. SELECT
    2. PROT_COM_HEADER.SYSTEM_TIME,
    3. PROT_COM_HEADER.Machine,
    4. PROT_COM_HEADER.RunOutErrorPinion,
    5. PROT_COM_HEADER.RunOutErrorGear,
    6. PROT_COM_HEADER.BestPos_Deviat_J,
    7. PROT_COM_HEADER.[Description],
    8. PROT_SFT_STD_Orders_Mesh_REF.REF_DMESH,
    9. PROT_SFT_STD_Orders_Mesh_REF.REF_CMESH
    10. FROM
    11. PROT_COM_HEADER, PROT_SFT_STD_Orders_Mesh_REF
    12. WHERE
    13. PROT_COM_HEADER.SYSTEM_TIME = PROT_SFT_STD_Orders_Mesh_REF.SYSTEM_TIME
    14. AND abs(datediff(d,PROT_COM_HEADER.SYSTEM_TIME,getdate())) <= 3
    15. ORDER BY PROT_COM_HEADER.SYSTEM_TIME ASC
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width