存储过程出现错误.关键字'ORDER'附近有语法错误.')'附近有语法错误.

ALTERPROCEDURE[getArticles]@keywordvarchar(20),@startRowIndexint,@maximumRowsint,@cat... ALTER PROCEDURE [getArticles]
@keyword varchar(20),
@startRowIndex int,
@maximumRows int,
@categoryID int,
@totalRows int output,
@preRowIndex int output,
@nextRowIndex int output
AS

DECLARE @first_id int,@startRow int

SET @startRowIndex = (@startRowIndex-1)*@maximumRows

IF @startRowIndex = 0
SET @startRowIndex = 1

SET ROWCOUNT @startRowIndex
if @keyword=''
SELECT @first_id = ID FROM article where categoryID=@categoryID ORDER BY ID
else SELECT @first_id = ID FROM article where categoryID=@categoryID and title like '%'+@keyword+'%' ORDER BY ID

PRINT @first_id
SET ROWCOUNT @maximumRows

if @keyword=''
(
SELECT * FROM [article] WHERE ID>=@first_id and categoryID=@categoryID ORDER BY ID
SELECT @preRowIndex=max(ID) FROM [article] WHERE ID>=@first_id-@maximumRows and ID<@first_id
SELECT @nextRowIndex=max(ID) FROM [article] WHERE ID>=@first_id+@maximumRows and ID<@first_id+2*@maximumRows
)
else SELECT * FROM [article] where ID>=@first_id and categoryID=@categoryID and title like '%'+@keyword+'%' ORDER BY ID

SET ROWCOUNT 0

if @keyword=''
SELECT @totalRows = COUNT(ID) FROM [article] where categoryID=@categoryID
else SELECT @totalRows = COUNT(ID) FROM [article] where categoryID=@categoryID and title like '%'+@keyword+'%'
展开
 我来答
百情稽凌春
2019-05-05 · TA获得超过1072个赞
知道小有建树答主
回答量:2803
采纳率:100%
帮助的人:15.8万
展开全部
因为order是sql的关键字,如果你用它作表名或字段名,在sql语句中使用时,要用方括号括起来,这样数据库就知道这不是一个关键字而是一个表名或字段名了.改后如下:
string
sql
="insert
into
[order]
([username],flag,ordertime)
values(
'"
+
session["username"].tostring()
+
"','"
+
0
+"',
convert(datetime,'"
+
datetime.today.toshortdatestring()
+
"',120))";
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
华夏日长兴
2009-09-02 · TA获得超过9595个赞
知道大有可为答主
回答量:6305
采纳率:85%
帮助的人:3935万
展开全部
把 ( 换成begin,把 ) 换成end ,一切OK ,我在我这边测试过了,保证没问题
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式