Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Posts
    1

    Unanswered: Make Dynamic cursor

    I want to a create cursor, data get in this cursor is got from a table which i don't know name (the name table can change). But i can't do the select to create this cursor by exec. Please help me, thanks.

  2. #2
    Join Date
    Feb 2003
    Location
    México
    Posts
    2

    Re: Make Dynamic cursor

    Originally posted by patexyz
    I want to a create cursor, data get in this cursor is got from a table which i don't know name (the name table can change). But i can't do the select to create this cursor by exec. Please help me, thanks.
    Try this:

    use pubs
    go

    declare @Table as Varchar(128)
    set @Table = 'Authors'

    declare @SQL Varchar(1000)

    set @SQL = ''

    set @SQL = @SQL + ' declare DYNCUR cursor for select * from ' + @Table
    set @SQL = @SQL + ' open DYNCUR'
    set @SQL = @SQL + ' fetch next from DYNCUR'
    set @SQL = @SQL + ' while @@fetch_status = 0'
    set @SQL = @SQL + ' begin'
    set @SQL = @SQL + ' fetch next from DYNCUR'
    set @SQL = @SQL + ' end'
    set @SQL = @SQL + ' close DYNCUR'
    set @SQL = @SQL + ' deallocate DYNCUR'

    exec(@SQL)

Posting Permissions

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