locked
Mysql count one to it RRS feed

  • Question

  • User-1290459327 posted

    Hi all,

    I have a stored procedure and i want

    If user excist update customers automaticly Increase column " Ordernr" with 1.

    My procedure is not working, but cannot find out why it is not working,

    Can u helps me?

    BEGIN
     IF EXISTS (select * from customers where Email = `@Email`) THEN
        update customers set Ordernr = Ordernr + 1 where Email = `@Email`;
      ELSE 
        insert into klanten (Email, Ww, FirstName, LastName, expenses) values (`@Email, @Ww, @FirstName, @LastName, @expenses`);
      END IF;
    END

     

    Thursday, November 5, 2015 3:38 PM

Answers

  • User-1290459327 posted

    Hi a2h,

    Thanks for replu but it isn't working, today i found what was wrong, i had to place ( ) in my update

    BEGIN
     IF EXISTS (select * from customers where Email = `@Email`) THEN
        update customers set Ordernr = (Ordernr + 1) where (Email = `@Email`);
      ELSE 
        insert into customers (Email, Ww, FirstName, LastName, expenses) values (`@Email, @Ww, @FirstName, @LastName, @expenses`);
      END IF;
    END

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 8, 2015 1:28 PM

All replies

  • User2103319870 posted

    My procedure is not working, but cannot find out why it is not working,

    You are using single quotes when using paramters, so the value which will pass to query is '@Email' instead of the value in variable.

    Try removing the single quotes like below

    BEGIN
     IF EXISTS (select * from customers where Email = @Email) THEN
        update customers set Ordernr = Ordernr + 1 where Email = @Email;
      ELSE 
        insert into klanten (Email, Ww, FirstName, LastName, expenses) values (@Email, @Ww, @FirstName, @LastName, @expenses);
      END IF;
    END

    Thursday, November 5, 2015 6:02 PM
  • User-1290459327 posted

    Hi a2h,

    Thanks for replu but it isn't working, today i found what was wrong, i had to place ( ) in my update

    BEGIN
     IF EXISTS (select * from customers where Email = `@Email`) THEN
        update customers set Ordernr = (Ordernr + 1) where (Email = `@Email`);
      ELSE 
        insert into customers (Email, Ww, FirstName, LastName, expenses) values (`@Email, @Ww, @FirstName, @LastName, @expenses`);
      END IF;
    END

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 8, 2015 1:28 PM