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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:22:51+00:00 2026-06-15T05:22:51+00:00

I have a stored procedure that works, but when I pass a value with

  • 0

I have a stored procedure that works, but when I pass a value with a hyphen in it, it errors.

I call my procedure with a value like call create(‘server-v01’,555); and I get the following error:

ERROR 1064 (42000): 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 ‘-v01’ at line 1

My procedure is as follows:

DELIMITER $$
CREATE PROCEDURE ct(tname varchar(20), sessionsnum INT(11))
BEGIN
DECLARE maxnum INT;
SET @s = CONCAT('INSERT INTO sessions_poll (server_name,sessions_num)                VALUES(''',tname,''',',sessionsnum,')');
PREPARE stm FROM @s;
EXECUTE stm;
SET @s = CONCAT('DROP TABLE IF EXISTS ', tname);
PREPARE stm FROM @s;
EXECUTE stm;
SET @s = CONCAT('CREATE TABLE ', tname, ' (num INT, max INT)');
PREPARE stm FROM @s;
EXECUTE stm;
SELECT @maxnum:=max(sessions_num) INTO maxnum FROM sessions_poll WHERE server_name=tname AND DATE(ts)=CURDATE();
SET @s = CONCAT('INSERT INTO ', tname, ' (num,max) VALUES (', sessionsnum,',',maxnum,')');
PREPARE stm FROM @s;
EXECUTE stm;
END $$
DELIMITER ;

My question is, how can I handle a variable with a hyphen in it?

  • 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-15T05:22:52+00:00Added an answer on June 15, 2026 at 5:22 am

    Your question is not how to handle variable with a dash, but how to handle a table with a dash. Your procedure tries to create a table with a name specified in tname. To create (or drop) a table like this you need to quote it with backticks.

    DROP TABLE IF EXISTS `server-01`;
    

    In particular you need to

    SET @s = CONCAT('DROP TABLE IF EXISTS `', tname, '`');
    

    and the same for other instances.

    Whether this is what you really want to do is a question, though 😉

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

Sidebar

Related Questions

I have a line in my SQL Stored Procedure that looks like this (works
I have a stored procedure that works in the mysql> terminal, but when I
I have a stored procedure that works correctly, but don't understand the theory behind
I have a stored procedure that I want to call from within another, and
I have a stored procedure that logs some data, how can I call this
I have an stored procedure that works on an table that contains xml field,
I have the following code that runs a stored procedure repeatedly. It works pretty
I have a Stored Procedure (SP) in which I pass in one value. In
I have a stored procedure on my server that inserts some parameters and returns
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to

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.