日期:2014-05-17 浏览次数:20524 次
如果是学方法,可以这样:
DECLARE @SqlT VARCHAR(200),@Str VARCHAR(20),@Id INT
SET @Str='1,2,3,4'
SET @SqlT='DECLARE SntCur CURSOR FOR
SELECT [Id] FROM [List] WHERE [Id] NOT IN('+@Str+') ORDER BY [Id] DESC)'
EXEC(@SqlT)
--出错原因:EXEC附近有语句错误,在游标中不能用EXEC吗?
OPEN SntCur
FETCH NEXT FROM Cur INTO @Id
WHILE @@FETCH_STATUS=0
BEGIN
--此处省略...
FETCH NEXT FROM Cur INTO @Id
END
CLOSE SntCur
DEALLOCATE SntCur