Advertisement

05.10.2008 at 06:10AM PDT, ID: 23391590
[x]
Attachment Details

MySQL 5 Stored procedure using conditional statement

Asked by bluefezteam in MySQL

Tags: MySQL, 5.0.45-community-nt, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS

Hi,

I'm trying to write a stored procedure that checks whether there is a row in the table for a product added to a shopping associated with that user, if so ammend quantity otherwise create a new row.

I am passing in 4 parameters as integers which are inUID, inPID, inQty, inPrice

When trying to run a query to create it I get the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS"

My stored procedure is below:

CREATE PROCEDURE sp_insert_basket_dev
      (IN inUID int,IN inPID int,IN inQty int,IN inPrice int)
AS
BEGIN
      IF EXISTS(SELECT PID AS selPID, Qty AS selQty FROM basket WHERE UID = inUID AND PID = inPID)
      BEGIN
            UPDATE basket SET Qty = selQty+inQty WHERE UID = inUID AND PID = inPID
      END
      ELSE
      BEGIN
            INSERT INTO basket (UID,PID,Qty,Price)
            VALUES (inUID,inPID,inQty,inPrice)
      END
END
GO


I hope someone can help shed some light onto a solutionStart Free Trial
[+][-]05.10.2008 at 06:14AM PDT, ID: 21538929

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 10:39AM PDT, ID: 21539816

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 12:16PM PDT, ID: 21540217

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 01:31AM PDT, ID: 21541836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 05:33AM PDT, ID: 21542297

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 08:22AM PDT, ID: 21542652

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MySQL
Tags: MySQL, 5.0.45-community-nt, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628