get data between dates

  • Table: TaskTable Current Date= 09/23/2009

    Task DueDate

    TaskA 09/21/2009

    TaskB 09/23/2009

    TaskC 09/25/2009

    TaskD 09/24/2009

    When i Select DueDate =09/23/2009 then i need to get TaskA and TaskB only

    When i Select DueDate =09/25/2009 then i need to get TaskC Only

    When i Select DueDate =09/24/2009 then i need to get TaskD Only

    pls help me out

  • kiran_ramisetti (9/23/2009)


    Table: TaskTable Current Date= 09/23/2009

    Task DueDate

    TaskA 09/21/2009

    TaskB 09/23/2009

    TaskC 09/25/2009

    TaskD 09/24/2009

    When i Select DueDate =09/23/2009 then i need to get TaskA and TaskB only

    When i Select DueDate =09/25/2009 then i need to get TaskC Only

    When i Select DueDate =09/24/2009 then i need to get TaskD Only

    pls help me out

    Please explain your output.

    Why does Select DueDate = 09/23/2009 return TaskA and TaskB only?

    Why does Select DueDate = 09/25/2009 return TaskC only?

    Why does Select DueDate = 09/24/2009 return TaskD only?

  • I made the assumption that you want any task that is due today or in the past.

    create table #Task (Task varchar(10), Due smalldatetime)

    insert #Task select 'TaskA','09/21/2009'

    insert #Task select 'TaskB','09/23/2009'

    insert #Task select 'TaskC','09/25/2009'

    insert #Task select 'TaskD','09/24/2009'

    if the date today is 9/23/2009 (any time after midnight)

    then this query will work for you.

    SELECT * FROM #TASK WHERE DUE < getdate()

    Task Due

    ---------- ------------------------------------------------------

    TaskA 2009-09-21 00:00:00

    TaskB 2009-09-23 00:00:00

  • Chuck Lucking (9/23/2009)


    I made the assumption that you want any task that is due today or in the past.

    create table #Task (Task varchar(10), Due smalldatetime)

    insert #Task select 'TaskA','09/21/2009'

    insert #Task select 'TaskB','09/23/2009'

    insert #Task select 'TaskC','09/25/2009'

    insert #Task select 'TaskD','09/24/2009'

    if the date today is 9/23/2009 (any time after midnight)

    then this query will work for you.

    SELECT * FROM #TASK WHERE DUE < getdate()

    Task Due

    ---------- ------------------------------------------------------

    TaskA 2009-09-21 00:00:00

    TaskB 2009-09-23 00:00:00

    Based on the original post, I don't think that is what is wanted. I'm waiting for the OP to explain the desired results as given in the original post.

  • that query need to written based on duedate,

    current date =2009/09/23

    but i have tasks on 21st, 22nd, 25th and 28th of 9th month and 2009

    when i select current date(2009/09/23) then i need to get 21st, 22nd and 23rd taks,

    when i select date(25th-09-2009) then i need to get only 25th task

    when i select date(28th-09-2009) then i need to get only 28th task

    only

  • The reply by grasshopper seems to be correct. You can make it general by passing the date you need.

    Let variable @datepassed be the date for which you match the records

    SELECT * FROM #task WHERE due< @datepassed

  • kiran_ramisetti (9/24/2009)


    that query need to written based on duedate,

    current date =2009/09/23

    but i have tasks on 21st, 22nd, 25th and 28th of 9th month and 2009

    when i select current date(2009/09/23) then i need to get 21st, 22nd and 23rd taks,

    when i select date(25th-09-2009) then i need to get only 25th task

    when i select date(28th-09-2009) then i need to get only 28th task

    only

    declare @passdate datetime

    set @passdate = '2009-09-30'

    /*Assume that getdate() is 2009-09-30*/

    if (datediff(day,getdate(),@passdate)> 0)

    begin

    SELECT Task FROM TaskTable

    WHERE DueDate = @passdate

    end

    else

    begin

    SELECT Task FROM TaskTable

    WHERE DueDate <= @passdate

    end

Viewing 7 posts - 1 through 6 (of 6 total)

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