Spliting One row of record into multiple row month wise betwen two dates

  • hello everyone can anybody help me out to do this: -

    My table data is like

    Datefiled Field1 Field2 Field2 Field4

    01-01-2012 ABC 10 15 17

    01-04-2013 PQR 7 80 65

    01-05-2014 XYZ 15 25 77

    Output should be like

    Month/Year Field1 Field2 Field2 Field4

    01/2012 ABC 10 15 17

    02/2012 ABC 10 15 17

    03/2012 ABC 10 15 17

    04/2012 ABC 10 15 17

    .....

    03/2013 ABC 10 15 17

    04/2013 PQR 7 80 65

    05/2013 PQR 7 80 65

    06/2013 PQR 7 80 65

    07/2013 PQR 7 80 65

    .......

    04/2014 PQR 7 80 65

    05/2014 XYZ 15 25 77

    Kindly reply with sql query/stored procedure to do the above job done.

  • A few questions...

    1. what's your date format? is that MM-DD-YYYY or DD-MM-YYYY?

    2. please explain in English how to get your expected answer. (what does your data mean?)

    Another thing... if you post your data like this, so people can play with it without having to build it themselves, post it like this:

    SELECT '01-01-2012' AS SomeDate, 'ABC' AS Field1, 10 AS Value1, 15 AS Value2, 17 AS Value3

    UNION ALL

    SELECT '01-04-2013', 'PQR', 7, 80, 65

    UNION ALL

    SELECT '01-05-2014', 'XYZ', 15, 25, 77;

    If you do that, you're far more likely to get tested code in response to your question.

  • My date format is YYYY-MM-DD and my output should like

    MM/YYYY Filed1 Field 2 Field2

    MM/YYYY (next month) Filed1 Field 2 Field2 (copy previous value)

    ...so on until Next Date found

    MM/YYYY Filed1 Field 2 Field2 (Records corresponding to next date)

    MM/YYYY (next month) Filed1 Field 2 Field2 (copy previous value)

    ...so on until Next Date found

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

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