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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:23+00:00 2026-06-16T00:38:23+00:00

In a MYSQL Stored-Procedure I need to select both the table columns, and select

  • 0

In a MYSQL Stored-Procedure I need to select both the table columns, and select columns into variables for further use within that procedure.

Below, a simplified version of the stored-procedure.

DECLARE pUSR_ID BIGINT;
DECLARE pPRJ_ID BIGINT;
DECLARE pUSR_LAN_ID BIGINT;

SELECT USR_ID, USR_Login, USR_Password, USR_Archived, USR_Deleted, 
  USR_ID, USR_PRJ_ID, USR_LAN_ID INTO pUSR_ID, pPRJ_ID, pUSR_LAN_ID
FROM tblUsers
WHERE USR_Login = 'foobar';

When I execute the above stored-procedure, I get the following error message, which makes sense.

Error Code: 1222. The used SELECT statements have a different number of columns

So, I placed the variables first, and the other columns after the variables.

SELECT USR_ID, USR_PRJ_ID, USR_LAN_ID INTO pUSR_ID, pPRJ_ID, pUSR_LAN_ID,
  USR_ID, USR_Login, USR_Password, USR_FullName, USR_IsProjectAdmin, USR_Archived,
  USR_Deleted


Executing this returns: Error 1327: Undeclared variable: USR_ID. I understand why I am getting the error.

What I don't understand is how I can both select the table columns and select certain columns into variables in the same statement?

  • 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-16T00:38:24+00:00Added an answer on June 16, 2026 at 12:38 am
    /*
    DECLARE pUSR_ID BIGINT;
    DECLARE pPRJ_ID BIGINT;
    DECLARE pUSR_LAN_ID BIGINT;
    */ /*no need to declare*/
    
    
    SELECT 
    @pUSR_ID:=USR_ID, 
    USR_Login, 
    USR_Password, 
    USR_Archived, 
    USR_Deleted, 
    USR_ID, 
    @pPRJ_ID:=USR_PRJ_ID, 
    @pUSR_LAN_ID:=USR_LAN_ID 
    FROM tblUsers
    WHERE USR_Login = 'foobar';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You have 2 MySQL stored procedures, both that select return codes at the end.
I have a MYSQL stored procedure SP1() that returns a result set. I want
I have ported a search from Coldfusion into a MySQL stored procedure. The actual
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
I need to convert the following stored procedure of SQL Server to MySQL. I
I'm writing a function that I need to use either a TABLE variable for
I've got a stored procedure in my MySQL database, and need to figure out
I have a stored procedure that opens a CURSOR on a select statement that
I need to add a new stored procedure on our company's MySQL server. Since
I have a mysql stored procedure from this ( google book ), and one

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.