Set @SqlstrGetCount = 'SELECT @TotalRowsCount = COUNT(*) FROM EventLog where '
DECLARE @ParameterDefinition Nvarchar(4000)
SET @ParameterDefinition = '
@TotalRowsCount int ,
@EventLogType tinyint,
@Category nvarchar(20),
@UserName nvarchar(20),
@BeginTime dateTime,
@EndTime dateTime'
EXEC sp_executesql @SqlstrGetCount, @ParameterDefinition ,@TotalRowsCount ,@EventLogType,@Category,@UserName,@BeginTime,@EndTime
发现 @TotalRowsCount 始终为0 ,百思不得其解,后来只好换为:
Set @SqlstrGetCount = 'SELECT COUNT(*) as TotalRowsCount FROM EventLog where '
DECLARE @ParameterDefinition Nvarchar(4000)
SET @ParameterDefinition = '
@EventLogType tinyint,
@Category nvarchar(20),
@UserName nvarchar(20),
@BeginTime dateTime,
@EndTime dateTime'
EXEC sp_executesql @SqlstrGetCount, @ParameterDefinition ,@EventLogType,@Category,@UserName,@BeginTime,@EndTime
DECLARE @ParameterDefinition Nvarchar(4000)
SET @ParameterDefinition = '
@TotalRowsCount int ,
@EventLogType tinyint,
@Category nvarchar(20),
@UserName nvarchar(20),
@BeginTime dateTime,
@EndTime dateTime'
EXEC sp_executesql @SqlstrGetCount, @ParameterDefinition ,@TotalRowsCount ,@EventLogType,@Category,@UserName,@BeginTime,@EndTime
发现 @TotalRowsCount 始终为0 ,百思不得其解,后来只好换为:
Set @SqlstrGetCount = 'SELECT COUNT(*) as TotalRowsCount FROM EventLog where '
DECLARE @ParameterDefinition Nvarchar(4000)
SET @ParameterDefinition = '
@EventLogType tinyint,
@Category nvarchar(20),
@UserName nvarchar(20),
@BeginTime dateTime,
@EndTime dateTime'
EXEC sp_executesql @SqlstrGetCount, @ParameterDefinition ,@EventLogType,@Category,@UserName,@BeginTime,@EndTime
在MS SQL中,写函数时,参数一定不要忘了给范围大小,上次遇到这个问题查了我好久啊!~不知道其它数据库会不会也这样!