Solved

MYSQL Syntax Error

Posted on 2013-05-18
1
427 Views
Last Modified: 2013-05-18
Hi

I get an "unexpected END_OF_INPUT, expected IF" error on the following MYSQL statement , can anyone help please

delimiter //

CREATE PROCEDURE UPDuserdaily (IN P_UserID INT,IN P_UserDate DATETIME)
BEGIN
      IF NOT EXISTS (SELECT 1 FROM tbuserdaily WHERE UserID=P_UserID AND Date=P_UserDate) THEN
            INSERT tbuserdaily(UserID,Date) VALUES (P_UserID,P_UserDate);
      
      UPDATE tbuserdaily
      SET Distance = (SELECT SUM(Distance) FROM tbjourney
                              WHERE UserID=P_UserID AND JourneyDateDate=P_UserDate)
      WHERE UserID=P_UserID AND Date=P_UserDate;

END//

DELIMITER ;
0
Comment
Question by:prices1964
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
Juan Ocasio earned 500 total points
ID: 39177136
Try ending the IF with an END IF

delimiter //

CREATE PROCEDURE UPDuserdaily (IN P_UserID INT,IN P_UserDate DATETIME)
BEGIN
      IF NOT EXISTS (SELECT 1 FROM tbuserdaily WHERE UserID=P_UserID AND Date=P_UserDate) THEN
            INSERT tbuserdaily(UserID,Date) VALUES (P_UserID,P_UserDate);
      
      UPDATE tbuserdaily
      SET Distance = (SELECT SUM(Distance) FROM tbjourney
                              WHERE UserID=P_UserID AND JourneyDateDate=P_UserDate)
      WHERE UserID=P_UserID AND Date=P_UserDate;
      END IF;
END//

DELIMITER ; 

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question