Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    5

    Question Unanswered: how to retrieve records one by one from the select query

    how to retrieve records one by one from the select query. here each record is a table name. Go to do some update statement on these table names.

    please help.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    What database and programming language are you using?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    May 2009
    Posts
    5
    Sybase. These stmts should come in a stored procedure.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Ok, I've hijacked your thread from the "Other PC Databases" forum into the Sybase forum. It will get more attention from Sybase users, and probably more comment here.

    You need to explain the "real world" part of your problem instead of just the "geek speak" for how you intended to solve it for the folks here because there may be Sybase-specific ways to do a better job than the brute force that I'm going to suggest. Ask the folks that know, you'll get better answers!

    The basic idea of what you want is a cursor. You'll have to figure out the specifics, but the gist of the cursor idea is:
    Code:
    DECLARE zFoo CURSOR FOR SELECT
       CharCol, DateCol
       FROM myTable
       WHERE 'Foo' = Bar
    
    OPEN zFoo
    FETCH zFoo INTO @CharVar, @DateVar
    
    WHILE 0 = @@FETCH_STATUS
       BEGIN
          IF GetDate() = @DateVar
             BEGIN
                PRINT 'Today is somebody''s birthday!'
                SELECT 'But I'm not saying that it is ', @CharVar
             END
          FETCH zFoo INTO @CharVar, @DateVar
       END
    
    CLOSE zFoo
    DEALLOCATE zFoo
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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