Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Posts
    2

    Unhappy Unanswered: Newbie HELP (ON SQL)

    Hi all
    I am very new to SQL and trying to select some records from a M/S
    SQL database to display 7 days worth of data

    My date column is set as a small date UK format

    15/10/2002 00:33:13

    Would I use the commands something like this

    Select *
    From my database
    Where my table between GETDATE () AND GETDATE ()-7


    Can anybody help as i am real lost

  2. #2
    Join Date
    Dec 2002
    Posts
    2

    Re: Newbie HELP (ON SQL)

    ohhh found it

    SELECT Whatever, WhateverElse FROM TableName WHERE DateField >= DATEADD(d, -7, GETDATE())

    Originally posted by webstep
    Hi all
    I am very new to SQL and trying to select some records from a M/S
    SQL database to display 7 days worth of data

    My date column is set as a small date UK format

    15/10/2002 00:33:13

    Would I use the commands something like this

    Select *
    From my database
    Where my table between GETDATE () AND GETDATE ()-7


    Can anybody help as i am real lost

  3. #3
    Join Date
    Dec 2002
    Location
    London, Ontario - Canada
    Posts
    3
    If you put this at the top of your script:

    declare @date1 datetime, @date2 datetime
    set @date2 = convert(varchar(11), getdate(), 111)
    set @date1 = convert(varchar(11), getdate()-7, 111)

    ...then you can just use @date1 as your from date and @date2 as your to date. You won't have to put in any dates.

    Steve

Posting Permissions

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