Well guys i answered my own question:
The trick is to put the whole thing into one statement.
if anyone knows a better way, please post it
declare @xxx varchar (5000)
declare @pTableName varchar (10)
declare @pNew varchar(6)
declare @pOld varchar(6)
declare @ID1 as varchar (6)
set @ID1 = 'ID1'
set @pTableName = 'JoshTemp'
set @pOld = 'josh2'
set @pNew = 'josh'
set @xxx = "
declare @ID2 varchar (6)
declare TmpCur cursor
for " +
"Select " + @ID1 + " from " + @pTableName + " where " + @id1 + " = '" + @pOld + "'" +
" open TmpCur
fetch next from TmpCur into @ID2
while (@@fetch_status <> -1)
begin
update " + @pTableName +
" set " + @ID1 + " = '" + @pNew + "'
where current of TmpCur
fetch next from TmpCur into @Id2
end
deallocate TmpCur"
exec( @xxx)
[sig][/sig]