分页使用SQL服务器,参数错误 [英] Pagination using SQL server ,parameter error

查看:77
本文介绍了分页使用SQL服务器,参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







Hi,


CREATE PROCEDURE [dbo].[spStudentListPagination] 
    
     @start int = 0,
     @pageCount int=0

AS
BEGIN
   
     Set NOCOUNT ON
     SELECT TOP @pageCount * FROM 
     (
          SELECT 
       [STNO]
      ,[SNAME]
      ,[MAJOR]
      ,[CLASS]
      ,[BDATE]
      , ROW_NUMBER() OVER (ORDER BY STNO) AS num
      FROM [student_db].[dbo].[Student]
     ) AS a
     WHERE num > @start
END







产生错误








it generating the error


Msg 102, Level 15, State 1, Procedure spStudentListPagination, Line 9
Incorrect syntax near ''@pageCount''.
Msg 156, Level 15, State 1, Procedure spStudentListPagination, Line 19
Incorrect syntax near the keyword ''AS''.







当我给@start和@pagecount提供直接值时结果是正确选择表数据..




when i am giving the direct value to @start and @pagecount The result is selecting the table data properly..

推荐答案

嗨基督徒,



尝试一下。



Hi Christian,

Try it out .

  CREATE PROCEDURE GetBranchesnyPage 
    
     @start int = 0,
     @pageCount int=0
 
AS
BEGIN
   
    
     Set NOCOUNT ON
     SELECT  * FROM 
     (
          SELECT 
       [Id]
      ,[BranchName]
      ,[CountryCode] 
      , ROW_NUMBER() OVER (ORDER BY Id) AS num
      FROM Branches
     ) AS A
     WHERE num > @start and num <=(@start+@pageCount)
END







我希望它可以帮助你


最好的




I hope it can help you

All the best


SQL Server不支持此功能。遗憾的是,您需要创建一行SQL并使用EXEC来执行此操作。
SQL Server does not support this. Sadly, you need to create a line of SQL and use EXEC, to do this.


这篇关于分页使用SQL服务器,参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆