Help me make it faster/better

  • Okay guys, here's what I'm trying to do.  I've got a table that looks like the following:

    Column1  Column2  Column3

    NULL         Name1       Name2

    (The column names are Column1, Column2, etc.  Name1, Name2, etc are the field values.  The table can have any number of columns.  I just use three here for simplicity.)

    I want to add a number of records, as determined by counting the underlying number of records in another table, that makes the table look like the following:

    Column1  Column2  Column3

    NULL         Name1      Name2

    1              NULL        NULL

    2              NULL        NULL

    3              NULL        NULL

    4              NULL        NULL

    5              NULL        NULL

    6              NULL        NULL

    .              NULL        NULL

    .              NULL        NULL

    .              NULL        NULL

    n              NULL        NULL

    (where n = my maximum number)

    Then I want to populate each column with the results of a query of another table.  The results will be a list of numbers for the associated name.  For example:

    SELECT thedate, thenumbers

    FROM tableA

    WHERE the_name = 'Name1'

    ORDER BY thdate

    When I get this data, there could be any number of results from 0 to the maximum number of rows I just entered.  I want to put "thenumbers" into each record based on the record number it is. 

    For example, if I get the following results from my second query:

    1/1/2004 15

    1/2/2004 17

    1/3/2004 43

    I want to input these numbers so the first table now looks like the following:

    Column1  Column2  Column3

    NULL         Name1      Name2

    1              15           NULL

    2              17           NULL

    3              43           NULL

    4              NULL        NULL

    5              NULL        NULL

    6              NULL        NULL

    .              NULL        NULL

    .              NULL        NULL

    .              NULL        NULL

    n              NULL        NULL

    I would then repeat this for each column.

    I am really looking for the fastest way of doing this.  I have it working but it is using cursors and WHILE loops and it is really taking too long.

    All help is greatly appreciated.

    ----------------------------------------------------------01010011010100010100110000100000010100110110010101110010011101100110010101110010001000000101001001101111011000110110101101110011

  • Never mind.  I finally got it working about as good as it's gonna get.

    ----------------------------------------------------------01010011010100010100110000100000010100110110010101110010011101100110010101110010001000000101001001101111011000110110101101110011

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

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