关键字 'Order' 附近有语法错误
SET ANSI_NULLS ONGO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_OrderAdd]
(
@UserID [varchar](50),
@BookID [int],
@OrderBeginDate [datetime],
@OrderEndDate [datetime],
@info [int] output
)
AS
BEGIN
if exists(select * from Book where BookID=@BookID)
begin
if exists(select * from Order where UserID=@UserID and BookID=@BookID and Orderstate=2)
set @info=1
else
begin
if((select (BookTotalNum-Loanedcount) from Book where BookID=@BookID )<1)
set @info=2
else
begin
insert into Order(UserID,BookID,OrderBeginDate,OrderEndDate)
values (@UserID,@BookID,@OrderBeginDate,@OrderEndDate)
update Book set Loanedcount=Loanedcount+1 where BookID=@BookID
set @info=3;
end
end
end
else
set @info=4
END
那位大神能够帮忙解决一下不胜感激! --------------------编程问答-------------------- order是关键字,你拿来当表名的话,要加上方括号
if exists(select * from [Order] where UserID=@UserID and BookID=@BookID and Orderstate=2)
其它地方也检查一下有没有加上 --------------------编程问答-------------------- 關鍵字衝突~ --------------------编程问答-------------------- if exists(select * from Order where UserID=@UserID and BookID=@BookID and Orderstate=2)
这句修改为:
if exists(select * from [Order] where UserID=@UserID and BookID=@BookID and Orderstate=2)
--------------------编程问答-------------------- 关键字 --------------------编程问答-------------------- 记得结贴 --------------------编程问答-------------------- 又是数据库保留字order惹的祸
如果数据库字段你使用了数据库中的保留字,请使用[]将其包裹起来,以示区别 --------------------编程问答-------------------- oracle 'order'
sql [order] --------------------编程问答-------------------- 不要拿关键字当表名哦~ --------------------编程问答-------------------- 嗯,规范一下命名规则就好了 --------------------编程问答-------------------- 学习中,保留字引发的血案啊 --------------------编程问答-------------------- 表名前面统统加个t,以示区别 --------------------编程问答-------------------- 关键字用以表名和列名必须加"[]" 以免冲突! --------------------编程问答--------------------
+1 --------------------编程问答-------------------- 楼上的都说的很清楚了 关键词 --------------------编程问答-------------------- --------------------编程问答-------------------- 关键子 --------------------编程问答--------------------
up. --------------------编程问答-------------------- 温馨提醒:版主,该结贴了!!! --------------------编程问答-------------------- 找到问题了,结贴吧 --------------------编程问答-------------------- insert into Order(UserID,BookID,OrderBeginDate,OrderEndDate)
Order关键字 --------------------编程问答-------------------- [order] 关键字 用[]括起来
补充:.NET技术 , ASP.NET