title: Cursor not open
body: <p>I'm trying to create table using statements stored in table. I'm using a cursor with execute(sql) as below:</p>
  
  <pre><code>create table tab
  (
    CreateSql varchar(250)
  )
  
  insert into tab values ('create table tab1 (id int )')
  insert into tab values ('create table tab2 (id int )')
  insert into tab values ('create table tab3 (id int )')
  
    declare cur cursor for
      select createsql
        from tab  
  
    declare @sql varchar(255)
  
    open cur
    fetch cur into @sql
  
    while @@SqlStatus = 0
      begin           
        execute(@Sql)               
        fetch cur into @sql
      end
  
    close cur
    deallocate cursor cur
  </code></pre>
  
  <p>If I run it then appears an error :</p>
  
  <blockquote>
    <p>Could not execute statement. Cursor not open SQLCODE=-180, ODBC 3
    State="34000"</p>
  </blockquote>
  
  <p>The first table (tab1) will create, but other (tab2, tab3) tables not.</p>
  
  <p>If I replace statement execute(sql) with select sql, script will work correctly.</p>
  
  <p>Thanks in advance for your answer.</p>
  
  <p>PX</p>