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 6760155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:01+00:00 2026-05-26T14:02:01+00:00

I am trying to write a store procedure in phpmyadmin but I get this

  • 0

I am trying to write a store procedure in phpmyadmin but I get this error, also I did it in navicat but I get the same error, can someone help me to fix it?, help really appreciated thanks

#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 ‘ IN comienzo int, IN termino int ) BEGIN SELECT usuario.nombre, LEF’ at line 2

this is my store procedure:

    CREATE PROCEDURE store(
  IN actualUser varchar(20)
)

SET @comienzo2 = comienzo;
SET @termino2 = termino;
SET @actualUser2 = actualUser;

BEGIN
SELECT
usuario.nombre,
LEFT(titulo, 20) as titulo,
LEFT(mensaje, 20) as mensaje,
correo.fecha,
correo.id_correo,
correo_has_usuario.correo_id_correo,
correo_has_usuario.destinatario_id_usuario,
correo_has_usuario.eliminado,
correo_has_usuario.leido
FROM
correo_has_usuario 
Inner Join correo ON correo_has_usuario.correo_id_correo = 
correo.id_correo
Inner Join usuario ON usuario.id_usuario = 
correo.usuario_id_usuario
WHERE
correo_has_usuario.destinatario_id_usuario = actualUser AND
correo_has_usuario.eliminado =  0 ORDER BY correo.fecha DESC
LIMIT comienzo,termino;
END$$

Hello thanks again for answer I get this error message #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 ‘SET @termino2 = termino; SET @actualUser2 = actualUser; BEGIN PREPARE stmt ‘ at line 8

  • 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-05-26T14:02:01+00:00Added an answer on May 26, 2026 at 2:02 pm

    You’ve missed the data length off of the VARCHAR on line 2

    IN actualUser varchar(20) for example

    Your limit statement is also incorrect and will throw out an error. Limits must be numeric or a local variable when used in a stored procedure. See

    http://dev.mysql.com/doc/refman/5.5/en/select.html

    Within stored programs, LIMIT parameters can be specified using
    integer-valued routine parameters or local variables as of MySQL
    5.5.6.

    To do this you’d have to set up your arguments as variables like

    SET @comienzo2 = comienzo;
    SET @termino2 = termino;
    SET @actualUser2 = actualUser;
    

    Then rather than simply run your select statement you must prepare it then execute it.

    PREPARE stmt FROM 'SELECT ... LIMIT ?, ?';
    EXECUTE stmt USING @comienzo2, @termino2;
    DEALLOCATE PREPARE stmt;
    

    This will also be the case for your where statement.

    Example:

    DELIMITER $$
    CREATE PROCEDURE store(
      IN actualUser varchar(20),
      IN comienzo int,
      IN termino int
    )
    
    SET @comienzo2 := comienzo;
    SET @termino2 := termino;
    SET @actualUser2 := actualUser;
    
    BEGIN
    PREPARE stmt FROM 'SELECT
        usuario.nombre,
        LEFT(titulo, 20) as titulo,
        LEFT(mensaje, 20) as mensaje,
        correo.fecha,
        correo.id_correo,
        correo_has_usuario.correo_id_correo,
        correo_has_usuario.destinatario_id_usuario,
        correo_has_usuario.eliminado,
        correo_has_usuario.leido
        FROM
        correo_has_usuario 
        Inner Join correo ON correo_has_usuario.correo_id_correo = 
        correo.id_correo
        Inner Join usuario ON usuario.id_usuario = 
        correo.usuario_id_usuario
        WHERE
        correo_has_usuario.destinatario_id_usuario = ? AND
        correo_has_usuario.eliminado =  0 ORDER BY correo.fecha DESC
        LIMIT ?,?;'
    EXECUTE stmt USING @actualUser2, @comienzo2, @termino2;
    DEALLOCATE PREPARE stmt;
    END;
    $$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a syntax question I'm trying to write a store procedure
Hi I am trying hard to write a stored procedure in ISeries DB2 but
I'm trying to write this as part of stored procedure on SQL Server 2000.
I'm currently trying to write a stored procedure that can compute the biweekly periods
I'm trying to write a Stored Procedure which'll get a string, hash it with
I'm trying to write a stored procedure to select employees who have birthdays that
I am trying to write a stored procedure which selects columns from a table
I'm trying to write a stored procedure that will read an Excel file into
I'm trying to write a stored procedure in SQL that will : Make a
I am trying to write a stored procedure that will allow me to write

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.