Extract corresponding IDs from a Table

  • Dear all,

    I have a table called 'Weeks' which has two columns namely:

    1. ID (Primary Key, Auto Indexed, DataType: int)

    2. WeekStartDate (DataType: date)

    The WeekStartDate column contain dates falling on 'Monday' for the period of 75 years, i.e. from the year 2013 to 2088.

    I need to extract the corresponding IDs of the dates from the week table when querying the dates falling on 'Monday' between two given dates.

    For example:

    If I query for dates falling on 'Monday' between 01-01-2013 and 31-01-2013, the result would be as given below:

    07-01-2013

    14-01-2013

    21-01-2013

    28-01-2013

    I need to extract corresponding IDs for the dates of the query result as given above from the 'Weeks' table.

    Can any one please help providing me the SQL query statement for the above problem?

  • ramsai1973 (12/7/2012)


    Dear all,

    I have a table called 'Weeks' which has two columns namely:

    1. ID (Primary Key, Auto Indexed, DataType: int)

    2. WeekStartDate (DataType: date)

    The WeekStartDate column contain dates falling on 'Monday' for the period of 75 years, i.e. from the year 2013 to 2088.

    I need to extract the corresponding IDs of the dates from the week table when querying the dates falling on 'Monday' between two given dates.

    For example:

    If I query for dates falling on 'Monday' between 01-01-2013 and 31-01-2013, the result would be as given below:

    07-01-2013

    14-01-2013

    21-01-2013

    28-01-2013

    I need to extract corresponding IDs for the dates of the query result as given above from the 'Weeks' table.

    Can any one please help providing me the SQL query statement for the above problem?

    Please supply DDL and readily consumable sample data as per this article --> http://www.sqlservercentral.com/articles/Best+Practices/61537/%5B/url%5D.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • How about something like

    select WeekStartDate, ID

    from [Weeks]

    where WeekStartDate betwen @datestart and @dateend


    Cursors never.
    DTS - only when needed and never to control.

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

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