date

  • What would be the most efficient way to bring back information for a certain number of days. ie you only want to see 30 days of information in the query

  • Use a date column from your table in the WHERE clause to limit the # of days you want to bring back.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • John Rowan (3/15/2010)


    Use a date column from your table in the WHERE clause to limit the # of days you want to bring back.

    For example:

    SELECT

    oh.*

    FROM

    dbo.OrderHeader oh

    WHERE

    oh.OrderDate >= dateadd(dd, datediff(dd, 0, getdate()) - 30, 0);

  • Select

    client_id as Client,

    ApplicantFullName as ClientName,

    CounselorName as Counselor,

    lastapptdatetime,

    tdate,

    TUDCounselor,

    TDDate,

    FUD1,

    FUD2,

    FUD3,

    FUD11,

    FUD21,

    FUD31

    From PDT_Counselor_CO_View

    where coalesce (complete,0) <>1 or coalesce(tud,0) <> 1

    and tdate >= dateadd(dd, datediff(dd, 0, getdate()) - 30, 0)

    Order by client_id desc

    This is my query and I am trying to bring back only the last 30 days of info

  • Ittech03 (3/15/2010)


    Select

    client_id as Client,

    ApplicantFullName as ClientName,

    CounselorName as Counselor,

    lastapptdatetime,

    tdate,

    TUDCounselor,

    TDDate,

    FUD1,

    FUD2,

    FUD3,

    FUD11,

    FUD21,

    FUD31

    From PDT_Counselor_CO_View

    where coalesce (complete,0) <>1 or coalesce(tud,0) <> 1

    and tdate >= dateadd(dd, datediff(dd, 0, getdate()) - 30, 0)

    Order by client_id desc

    This is my query and I am trying to bring back only the last 30 days of info

    Try this change to your where clause:

    WHERE

    (coalesce (complete,0) <> 1 or coalesce(tud,0) <> 1)

    and tdate >= dateadd(dd, datediff(dd, 0, getdate()) - 30, 0)

  • another issue, how would you get the date to not display a date if a check box is not checked

  • Ittech03 (3/15/2010)


    another issue, how would you get the date to not display a date if a check box is not checked

    Sorry, don't understand the question. Please explain what you are attempting to do.

  • I have field with that is assocaited with another field, when that field is selected I want to be able to bring that date back to another field

  • Please see the article in my signature line and post an example of what you are looking for. This sounds easy enough, but we need to clearly understand what you are after. It's easiest to understand when we have example tables/data/resultsets.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply