ALTER PROCEDURE [dbo].[messageCountByWhere]
@where varchar(8000) = ' 1=1 ',
@recordCount int output
AS
SET NOCOUNT ON
declare @sqlCount nvarchar(4000)
set @sqlCount= 'SELECT @Count=count(-1) FROM [dbo].[message] WHERE ' +@where
--print @sqlCount
exec sp_executesql @sqlCount,N'@Count int output',@recordCount output
RETURN @@Error
count(-1)有啥意思 ? 还有 exec 中 N'@Count int output',@recordCount output 表示什么意思 , 希望给你解释
count(-1),count(1)等比count(*)的效率高.
count(-1) 这个还真没有见过
output 是输入输出参数
exec sp_executesql @sqlCount,N'@Count int output',@recordCount output
执行@sqlCount 并且把@count 的值赋给@recordCount
count(-1)表示和count(1)一样,统计行数,exec sp_executesql @sqlCount,N'@Count int output',@recordCount output表示:执行sp_executesql的存储过程,后面是参数,然后返回Count和recordCount