Solved

MYSQL Syntax Error

Posted on 2013-05-18
1
422 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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now