Re: extract data from a table for the last 7 days

  • Hi i've written this bit of code to extract data from a table for the last 7 days, i just like to know id this the best way of going this.

     

    select open_dt

    from dbo.tbl_metrics_grca_fl

    where open_dt >= convert(datetime,convert(char(8),getdate()-7,112))

     

    Thanks

     

  • Here's another way that should run quicker.

    declare @then datetime

    set @then = DateAdd(Day, -7, getdate())

    select open_dt

    from dbo.tbl_metrics_grca_fl

    where open_dt >= @then

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

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

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