Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    Montevideo, Uruguay, South America
    Posts
    13

    Angry Unanswered: Cursors and "variable" table name

    Hi, gurus

    Im trying to declare a cursor that depends on the results of another cursor.

    The difficulty is here: the name of the table that is used in the select statement that defines the second cursor is retrieved from the first one. Quite a mess, don't you think?
    Here comes my code

    DECLARE toLoad cursor for
    select ...
    from meta_indicadores
    where ....

    OPEN toLoad
    FETCH NEXT FROM toLoad INTO @tableName, @column,...(other columns...)

    WHILE (@@fetch_status = 0)
    BEGIN
    DECLARE calculated CURSOR FOR
    (*) select @column from @tableName
    FETCH NEXT FROM calculado INTO @valorAlmacenado
    WHILE (@@fetch_status = 0)
    BEGIN
    END
    CLOSE calculated
    DEALLOCATE calculated
    FETCH NEXT FROM toLoad INTO @tableName, @column,...(other columns...)

    END

    CLOSE toLoad
    DEALLOCATE toLoad


    When I create the procedure, a syntax error appears "@tableName must be declared" but the variables HAS BEEN DECLARED!

    I have also tried replacing (*) with this code:
    exec('select '+@column+' from '+@tableName)

    but it doesn't work.

    Any suggestions??????
    Bye
    Lorena

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: Cursors and "variable" table name

    Why don't you tell us what you're trying to do...

    Looks like some kind of admin functions....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Sep 2003
    Posts
    522
    look into sp_msforeachxxx, you may not need cursors to do what you're trying to do.

  4. #4
    Join Date
    Oct 2003
    Location
    Montevideo, Uruguay, South America
    Posts
    13
    As a requirement of the project I'm working on we can't use an OLAP server, so any rollup agregation must be pre calcullated and stored

    It`s a table that will help me calculating agregations in a datawarehouse, not only agregations but also some kind of calculated members that depend on measures. This tables stores METADATA about aggregations (what to sum up, wich components, where its located, etc), and I want to use it to make the calculation process "cleaner"

    What I'm trying to do is to retrieve the table name and column name from this metadata table and then use it to calculate the agregation.
    Last edited by soy_lore_lore; 10-20-03 at 18:03.
    Bye
    Lorena

  5. #5
    Join Date
    Oct 2003
    Location
    Montevideo, Uruguay, South America
    Posts
    13

    Smile

    Hi guys!

    I have found another solution

    thanks a lot
    lorena
    Bye
    Lorena

Posting Permissions

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