Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:51:14+00:00 2026-06-10T12:51:14+00:00

I am converting a stored procedure from MS-SQL to MySQL. It is based around

  • 0

I am converting a stored procedure from MS-SQL to MySQL. It is based around Directed Acyclic Graphs but I am getting a syntax error.

The original MS-SQL script is in Listing 2 on the following page:
http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o

The error I get is:
#1064 – 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 ‘DECLARE varId int; INSERT INTO edges ( startVertex, en’ at line 36

The MySQL code:

DELIMITER //
CREATE PROCEDURE AddEdge(
IN iStartVertexId varchar(36),
IN iEndVertexId varchar(36),
IN iSource varchar(150)
)

MAIN_BLOCK: BEGIN

DECLARE counter int default 0;
SET counter = (SELECT id 
   FROM edges 
   WHERE startVertex = iStartVertexId 
     AND endVertex = iEndVertexId 
     AND hops = 0);
IF counter > 0 THEN
   BEGIN
      LEAVE MAIN_BLOCK;
   END;
END IF;

SET counter = 0;
SET counter = (SELECT Id 
                     FROM edges
                     WHERE StartVertex = @EndVertexId 
                       AND EndVertex = @StartVertexId);

IF iStartVertexId = iEndVertexId 
      OR counter > 0
THEN
BEGIN

     LEAVE MAIN_BLOCK;
END;
END IF;


DECLARE varId int;

INSERT INTO edges (
     startVertex,
     endVertex,
     hops,
     source)
  VALUES (
     iStartVertexId,
     iEndVertexId,
     0,
     iSource);

SELECT varId = LAST_INSERT_ID();
UPDATE edges
  SET entryEdgeId = varId
    , exitEdgeId = varId
    , directEdgeId = varId 
  WHERE id = varId;

-- step 1: A's incoming edges to B
INSERT INTO edges (
     entryEdgeId,
     directEdgeId,
     exitEdgeId,
     startVertex,
     endVertex,
     hops,
     source) 
  SELECT id
     , varId
     , varId
     , startVertex 
     , iEndVertexId
     , hops + 1
     , iSource
  FROM edges
  WHERE endVertex = iStartVertexId;

-- step 2: A to B's outgoing edges
INSERT INTO edges (
     entryEdgeId,
     directEdgeId,
     exitEdgeId,
     startVertex,
     endVertex,
     hops,
     source) 
  SELECT varId
     , varId
     , id
     , iStartVertexId 
     , endVertex
     , hops + 1
     , iSource
  FROM edges
  WHERE startVertex = iEndVertexId;

-- step 3: A’s incoming edges to end vertex of B's outgoing edges
INSERT INTO edges (
     entryEdgeId,
     directEdgeId,
     exitEdgeId,
     startVertex,
     endVertex,
     hops,
     source)
  SELECT A.id
     , varId
     , B.id
     , A.startVertex 
     , B.endVertex
     , A.hops + B.hops + 1
     , iSource
  FROM edges A
     CROSS JOIN edges B
  WHERE A.endVertex = iStartVertexId
    AND B.startVertex = iEndVertexId;

END //
DELIMITER ;

This works fine without the IF statements so I think my syntax is a bit wrong. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:51:15+00:00Added an answer on June 10, 2026 at 12:51 pm

    As stated under DECLARE Syntax:

    DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a stored procedure from MS-SQL to MySQL. It is based around
I'm working on converting a stored procedure from SQL server to Oracle. This stored
I'm converting a stored procedure in some software I'm maintaining from SQL Server SQL
Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going
I'm trying to call a stored procedure (on a SQL 2005 server) from C#,
Hi I am getting an error 'Conversion failed when converting date and/or time from
I'm having a never-ending problem with trying to call a stored procedure from a
I am converting a stored procedure which I had previously written as a string
Is there a way to write SQL Server Stored Procedure which to be strongly
I am trying to make one stored procedure only in SQL Server that lets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.