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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:17:54+00:00 2026-06-15T09:17:54+00:00

I am new to procedures and I am trying to implement them within my

  • 0

I am new to procedures and I am trying to implement them within my customer website.

I want to create a procedure to add a new customer. I want to check to make sure there phoneNumber is not already in the database. If it is, I want to display an error message. If the phone number is not in the db, I want to insert it into my CUSTOMER table.

I have implemented the following but I am getting an error. I am not sure if I am declaring variables right in MySQL, and I am not sure if the “if statement” is valid in the way I have done it. Also, how could I set the if statement query to a variable? If anyone could help, it would mean a lot. Thanks!

DELIMITER //
CREATE PROCEDURE add_Customer
(IN customerNum int, 
IN last varchar, 
IN first varchar)
BEGIN
DECLARE output var DEFAULT '';
IF SELECT CUSTOMER.customerNum FROM CUSTOMER WHERE CUSTOMER.customerNum= customerNum 
THEN
SET output= "Customer already exists!";
select output;
ELSE
INSERT INTO CUSTOMER VALUES (customerNum, last, first);
END IF;
END//
DELIMITER;

EDITED

DELIMITER //
CREATE PROCEDURE add_Customer
(IN customerNum int, 
IN last varchar, 
IN first varchar)
BEGIN
DECLARE output var DEFAULT '';
DECLARE var_num INT;
SELECT CUSTOMER.customerNum INTO var_num FROM CUSTOMER WHERE CUSTOMER.customerNum= customerNum 
if var_num IS NULL THEN
INSERT INTO CUSTOMER VALUES (customerNum, last, first);
ELSE
SET output= "Customer already exists!";
select output;
END IF;
END//
DELIMITER;
  • 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-15T09:17:54+00:00Added an answer on June 15, 2026 at 9:17 am

    Try:

    DECLARE var_num INT;
    SELECT CUSTOMER.customerNum INTO var_num FROM CUSTOMER WHERE CUSTOMER.customerNum= customerNum
    IF var_num IS NULL THEN
        INSERT INTO CUSTOMER VALUES (customerNum, last, first);
    ELSE
        SET output= "Customer already exists!";
        select output;
    ENDIF;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new stored procedures and trying to write a procedure to duplicate user(by
I'm new to stored procedures and trying to add a composite primary key to
I am very new to SQL Server Stored Procedures, I am trying to create
I an trying to create new stored procedures. Below is the code segment for
I am very new to stored procedures. I am trying to create a stored
I am very new to stored procedures. I am trying to make a stored
I would like to create a template for new stored procedures for our development
new to c#. I'm trying to make a simple system where I can search
I'm a new developer trying to add new functionality to an old project. The
I'm trying to implement Facebook posting procedure. Can you help me to understand how

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.