存储过程出现错误.
来源:百度知道 编辑:UC知道 时间:2024/06/05 05:52:40
ALTER PROCEDURE [getArticles]
@startRowIndex int,
@maximumRows int,
@categoryID int,
@totalRows int output
AS
DECLARE @first_id int,@startRow int
SET @startRowIndex = (@startRowIndex-1)*@maximumRows
IF @startRowIndex = 0
SET @startRowIndex = 1
SET ROWCOUNT @startRowIndex
SELECT @first_id = ID FROM article where categoryID=@categoryID ORDER BY ID
PRINT @first_id
SET ROWCOUNT @maximumRows
SELECT * FROM [article] WHERE ID>=@first_id and categoryID=@categoryID ORDER BY ID
SET ROWCOUNT 0
SELECT @totalRows = COUNT(ID) FROM [article] where categoryID = @categoryID //错误计算表[article]中categoryID = @categoryID的数据条数.错误提示GO附近有错误.
GO
另外如果我要用到 like:
若有参数keyword为null 则不用like 怎么修改此存储过程?
where (title like @keyword)
@startRowIndex int,
@maximumRows int,
@categoryID int,
@totalRows int output
AS
DECLARE @first_id int,@startRow int
SET @startRowIndex = (@startRowIndex-1)*@maximumRows
IF @startRowIndex = 0
SET @startRowIndex = 1
SET ROWCOUNT @startRowIndex
SELECT @first_id = ID FROM article where categoryID=@categoryID ORDER BY ID
PRINT @first_id
SET ROWCOUNT @maximumRows
SELECT * FROM [article] WHERE ID>=@first_id and categoryID=@categoryID ORDER BY ID
SET ROWCOUNT 0
SELECT @totalRows = COUNT(ID) FROM [article] where categoryID = @categoryID //错误计算表[article]中categoryID = @categoryID的数据条数.错误提示GO附近有错误.
GO
另外如果我要用到 like:
若有参数keyword为null 则不用like 怎么修改此存储过程?
where (title like @keyword)
在存储过程中这种条件语句不是很简单吗?你先判断关键字,再来执行相应的sql语句不就可以了码。
if xxx is null
select xxx from xxx
else
select xxx from xxx where (title like @keyword)
endif
if xxx is null
select xxx from xxx
else
select xxx from xxx where (title like @keyword)
endif