计数附近的存储过程语法中的问题 [英] problem in storeprocedure syntax near count
本文介绍了计数附近的存储过程语法中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样创建存储过程,但是在@count和@ count == 0附近出现错误.谁能解决这个问题
i am creating the store procedure like this but getting error near @count and @count==0 . can anyone figuer out the problem
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddToCart]
@CustomerID varchar(50),
@ProductID int,
@Quantity int,
@Count int
@Count=select count (*) from table where ProductID=@ProductID;
If(@Count==0)
AS
BEGIN
INSERT INTO ShoppingCart
(CustomerID,Quantity,ProductID)
VALUES(@CustomerID,@Quantity,@ProductID)
END
推荐答案
很多语法不正确.它可能并不完美,但是您应该进行以下主要修改:
Lots of your syntax is incorrect. It may not be perfect, but here are the major modifications you should make:
ALTER PROCEDURE [dbo].[AddToCart]
@CustomerID varchar(50),
@ProductID int,
@Quantity int
AS
BEGIN
DECLARE @count int
SELECT @Count = COUNT(*) FROM table WHERE ProductID = @ProductID
IF @Count = 0
BEGIN
INSERT INTO ShoppingCart
(CustomerID,Quantity,ProductID)
VALUES(@CustomerID,@Quantity,@ProductID)
END
END
这篇关于计数附近的存储过程语法中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文