ALTER PROCEDURE [dbo].[PrAdViewLogGet] 
@ad_id int=null, --为空获取所有广告浏览记录,不为空则获取某一广告的浏览记录
@PageIndex int=1,
@PageSize int=20,
@Recount int=0 output,
    @flag tinyint=null
AS
BEGIN
DECLARE @strsql nvarchar(2000),@strRec nvarchar(2000)
SET @strsql=''
SET @strRec=''
SET @strsql=N'SELECT TOP '+@PageSize+' * FROM AdViewLog where ID not in (select TOP '+(@PageIndex-1)*@PageSize+' ID FROM AdViewLog)'
EXEC sp_executesql @strsql,N'@ad_id int',@ad_id    
SET @strRec=N'SELECT @Recount=COUNT(0) FROM AdViewLog '
EXEC sp_executesql @strRec,N'@ad_id int,@Recount int output',@ad_id,@Recount=@Recount output
END错误为
消息 245,级别 16,状态 1,过程 PrAdViewLogGet,第 26 行
在将 nvarchar 值 'SELECT TOP ' 转换成数据类型 int 时失败。