DECLARE vend_cursor
FOR select name from sys.objects where name LIKE 'SA%' and type='U' order by name
declare @objname varchar(100)
DECLARE @SQLString nvarchar(500)
DECLARE @ParmDefinition nvarchar(500)
DECLARE @cntAffect int
OPEN vend_cursor
FETCH NEXT FROM vend_cursor into @objname
SET @SQLString = N'SELECT @cntAffectOut =count(*) from '+@objname
SET @ParmDefinition = N'@cntAffectOut int OUTPUT';
EXECUTE sp_executesql @SQLString, @ParmDefinition, @cntAffectOut=@cntAffect OUTPUT
IF @cntAffect>0
BEGIN
select @objname
SET @SQLString='select top 10 * from '+@objname
EXECUTE sp_executesql @SQLString
END
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM vend_cursor into @objname
SET @SQLString = N'SELECT @cntAffectOut =count(*) from '+@objname
SET @ParmDefinition = N'@cntAffectOut int OUTPUT';
EXECUTE sp_executesql @SQLString, @ParmDefinition, @cntAffectOut=@cntAffect OUTPUT
IF @cntAffect>0
BEGIN
select @objname
SET @SQLString='select top 10 * from '+@objname
EXECUTE sp_executesql @SQLString
END
END
CLOSE vend_cursor;
DEALLOCATE vend_cursor;
SET NOCOUNT OFF
沒有留言:
張貼留言