Sql Problem!!
-
I write the following storePrpcedure:
create PROCEDURE [dbo].[Ins_Products]
-- Add the parameters for the stored procedure here
@ProductName nvarchar(max),
@ProductModel nvarchar(max),
@ProductColor nvarchar(50),
@ProductDescription nvarchar(max),
@ProductPrice bigint,
@ProductQuantity intAS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;-- Insert statements for procedure here
declare @ProductID bigint;
--set @ProductID=-1if Not Exists ( Select @ProductID = ProductID From Products Where ProductModel=@ProductModel) Begin Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity) Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity) select @ProductID=@@Identity End else Begin Update Products Set ProductName=@ProductName ,ProductModel=@ProductModel , ProductColor=@ProductColor, ProductDescription=@ProductDescription, ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity where (ProductID=@ProductID) End
return @ProductID
ENDbut it couse error:
Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
Incorrect syntax near the keyword 'else'.what should I do?!! ?!!!!!
modified on Friday, May 1, 2009 4:10 AM
-
I write the following storePrpcedure:
create PROCEDURE [dbo].[Ins_Products]
-- Add the parameters for the stored procedure here
@ProductName nvarchar(max),
@ProductModel nvarchar(max),
@ProductColor nvarchar(50),
@ProductDescription nvarchar(max),
@ProductPrice bigint,
@ProductQuantity intAS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;-- Insert statements for procedure here
declare @ProductID bigint;
--set @ProductID=-1if Not Exists ( Select @ProductID = ProductID From Products Where ProductModel=@ProductModel) Begin Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity) Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity) select @ProductID=@@Identity End else Begin Update Products Set ProductName=@ProductName ,ProductModel=@ProductModel , ProductColor=@ProductColor, ProductDescription=@ProductDescription, ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity where (ProductID=@ProductID) End
return @ProductID
ENDbut it couse error:
Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
Incorrect syntax near the keyword 'else'.what should I do?!! ?!!!!!
modified on Friday, May 1, 2009 4:10 AM
This is C# Forum. You should post the question in SQL Forum.
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net
-
I write the following storePrpcedure:
create PROCEDURE [dbo].[Ins_Products]
-- Add the parameters for the stored procedure here
@ProductName nvarchar(max),
@ProductModel nvarchar(max),
@ProductColor nvarchar(50),
@ProductDescription nvarchar(max),
@ProductPrice bigint,
@ProductQuantity intAS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;-- Insert statements for procedure here
declare @ProductID bigint;
--set @ProductID=-1if Not Exists ( Select @ProductID = ProductID From Products Where ProductModel=@ProductModel) Begin Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity) Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity) select @ProductID=@@Identity End else Begin Update Products Set ProductName=@ProductName ,ProductModel=@ProductModel , ProductColor=@ProductColor, ProductDescription=@ProductDescription, ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity where (ProductID=@ProductID) End
return @ProductID
ENDbut it couse error:
Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
Incorrect syntax near the keyword 'else'.what should I do?!! ?!!!!!
modified on Friday, May 1, 2009 4:10 AM