显示游标中的字符串SQL问题 !
alter proc procCheckProvider(
@columnsValue as varchar(100)
)
as
DECLARE @TName AS VARCHAR(50)
DECLARE @CName AS VARCHAR(50)
DECLARE @STR AS VARCHAR(1000)
DECLARE a1 CURSOR FOR
SELECT sysobjects.name,syscolumns.name as columnsName
FROM sysobjects INNER JOIN
syscolumns ON sysobjects.id = syscolumns.id
WHERE (sysobjects.xtype = 'u ') AND syscolumns.name = 'providerid ' order by sysobjects.name,syscolumns.name
OPEN a1
FETCH NEXT FROM a1 INTO @TName,@CName
WHILE @@FETCH_STATUS = 0
BEGIN
set @str= 'if EXISTS(select * from [ '+@tname+ '] where '+@cname+ '= ' ' '+@columnsValue+ ' ' ')
begin
if exists(select * from '+@tname+ ' where '+@cname+ '= ' ' '+@columnsValue+ ' ' ')
begin
select ' '出错 ' '
return --为什么这里的return不能返回?
end
end
'
--print @str
EXEC(@STR)
FETCH NEXT FROM a1 INTO @TName,@CName
END
CLOSE a1
DEALLOCATE a1
select ' '
在上面的return 不能返回呢?而是继续执行呢?
难道不能在那里用return吗?请问该用什么语句在那里返回?
------解决方案--------------------因为你返回时要关闭游标,所以可以这样来做
将return修改为goto Err1
goto Err1
end
end
'
--print @str
EXEC(@STR)
FETCH NEXT FROM a1 INTO @TName,@CName
END
CLOSE a1
DEALLOCATE a1
return
Err1:
CLOSE a1
DEALLOCATE a1