0

This is my code in MySQL.

USE database;
DROP procedure IF EXISTS CreateTable;
DELIMITER $$
USE ims_data$$
CREATE PROCEDURE CreateTable ()
    BEGIN
Set @SqlQuery = Concat('DROP TABLE IF EXISTS mytemptable;');
Set @SqlQuery = Concat(@SqlQuery,'\r\n','create table mytemptable');
Set @SqlQuery = Concat(@SqlQuery,'\r\n','(');
Set @SqlQuery = Concat(@SqlQuery,'\r\n','Column1 int,');
Set @SqlQuery = Concat(@SqlQuery,'\r\n','Column2 varchar(500)');
Set @SqlQuery = Concat(@SqlQuery,'\r\n',');');
Set @SqlQuery = Concat(@SqlQuery,'\r\n','Select * from mytemptable;');
#Select @SqlQuery;
PREPARE Statement From @SqlQuery;
EXECUTE Statement;  
DEALLOCATE PREPARE Statement;
END$$

DELIMITER ;


call GetUploadInformation();

I am trying to create a table but it is giving me an error.

Error Code: 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 'create table mytemptable (Stockist_Code int,Status varchar(500) ); Sele' at line 2

This is the output of query.

    DROP TABLE IF EXISTS mytemptable;
create table mytemptable
(
Column1 int,
Column2 varchar(500)
);
Select * from mytemptable;

Which is working fine when executing this code withoug calling the procedure.

1 Answer 1

2

PREPARE/EXECUTE can only process one statement at a time. You're trying to execute two with the ;.

The error message gives you a clue in that it ran the two statements together.

You'll have to run them as separate statements.

Sign up to request clarification or add additional context in comments.

2 Comments

I commented out each line and made only one statement then too it is giving the same error
If you comment out the line including the SELECT you won't have exactly the same error because at a minimum SELE won't be part of it. Try commenting out that line and ALSO removing the semicolon from the previous line, e.g. ');' becomes ')'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.