?
Solved

MYSQL Syntax Error

Posted on 2013-05-18
1
Medium Priority
?
435 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 15

Accepted Solution

by:
Juan Ocasio earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 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