一个SQL存储过程,执行报错,声明了提示未声明
一个存储过程执行出错,求教高手ALTERPROCEDURE[dbo].[SelectRizhi](@useridchar(16),@PageSizeint,@PageIn...
一个存储过程执行出错,求教高手
ALTER PROCEDURE [dbo].[SelectRizhi](@userid char(16),@PageSize int ,@PageIndex int)
-- Add the parameters for the stored procedure here
AS
declare @strsql varchar(150)=null
if @PageIndex=1
set @strsql='select top '+QUOTENAME(@PageSize,'()')+' rzId,userId,rzTitle from Rizhi where userId=@userid '
else
set @strsql='select top'+QUOTENAME(@PageSize,'()')+' * from Rizhi where userId=@userId and rzId not in
(select top '+QUOTENAME((@PageIndex-1)*@PageSize,'()')+' rzId from Rizhi )'
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
exec(@strsql)
print(@strsql)
END
执行传递参数@PageIndex=1,@pagesize=2,@userid=某字段名
结果报错
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@userid"。
select top (2) rzId,userId,rzTitle from Rizhi where userId=@userid
(1 行受影响) 展开
ALTER PROCEDURE [dbo].[SelectRizhi](@userid char(16),@PageSize int ,@PageIndex int)
-- Add the parameters for the stored procedure here
AS
declare @strsql varchar(150)=null
if @PageIndex=1
set @strsql='select top '+QUOTENAME(@PageSize,'()')+' rzId,userId,rzTitle from Rizhi where userId=@userid '
else
set @strsql='select top'+QUOTENAME(@PageSize,'()')+' * from Rizhi where userId=@userId and rzId not in
(select top '+QUOTENAME((@PageIndex-1)*@PageSize,'()')+' rzId from Rizhi )'
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
exec(@strsql)
print(@strsql)
END
执行传递参数@PageIndex=1,@pagesize=2,@userid=某字段名
结果报错
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@userid"。
select top (2) rzId,userId,rzTitle from Rizhi where userId=@userid
(1 行受影响) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询