While rowid and sqlstr are column names in your table, you are also using variables @rowid and @sqlstr in your code without ever declaring them. Add the declaration for them with the same data types as the columns at the beginning and you shoud be covered.