以下是我想建的一游标操作表,其中USysTables表中,name(用户表名),在红字行出错?请哪位大侠看看错在哪里?
ALTER PROCEDURE op_tableRight
AS
DECLARE @tablename sysname,@tableright int ,@right_date varchar(20)
DECLARE @strsql nvarchar(500)
DECLARE tableCursor CURSOR FOR
SELECT name, TableRight, Right_date FROM USysTables WHERE (Changs = 1)
Open tableCursor
FETCH FROM tableCursor into @tablename,@tableright,@right_date
While @@Fetch_Status=0
begin
select @tablename=rtrim(upper(@tablename))
IF EXISTS(SELECT name FROM '+ @tablename +' WHERE name like '+ @right_date +')
if @tableright > 0
exec('UPDATE '"+ @tablename +"' SET Find_sign = 1 where '+ @right_date +' ='+@tableright +')
FETCH Next FROM tableCursor into @tablename,@tableright,@right_date
end
close tableCursor
deallocate tableCursor