Results 1 to 4 of 4

Thread: DB Puzzle

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    DB Puzzle

    Any Date range within a week where the week start is monday and weekend is monday.
    No Name FromDate Tilldate
    1 ABCD 25-5-2010 25-5-2010
    2 DSFA 22-6-2010 23-6-2010
    3 WERQ 13-8-2010 19-8-2010

    From above table, use T-SQL to split the above date range and
    create a row for each date within the range like below

    No Name Date
    1 ABCD 25-5-2010
    2 DSFA 22-6-2010
    2 DSFA 23-6-2010
    3 WERQ 13-8-2010
    3 WERQ 14-8-2010
    3 WERQ 15-8-2010
    3 WERQ 16-8-2010
    3 WERQ 17-8-2010
    3 WERQ 18-8-2010
    3 WERQ 19-8-2010

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: DB Puzzle

    Can you create a table with all dates in it? That is the obvious and easiest way to deal with this.

    If you cannot do that then can you use a stored procedure to do this?

    Is this MS SQL server?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: DB Puzzle

    Yes. It is MS SQL.. u just consider above is the table with date range.. Can u give me the solution for that?

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: DB Puzzle

    I would create another table with "all dates" in it and then join to that - simple join - but before I go to the effort of showing you a solution that involves another table.

    Please answer my two other questions.

    I did ask them - I would not have asked them if it didn't matter.

    Why don't people answer questions put to them on the forum - it drives me totally insane!!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width