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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:25+00:00 2026-05-27T11:50:25+00:00

I have the following stored procedure. It does not seem to work. Is there

  • 0

I have the following stored procedure. It does not seem to work. Is there anything that I’m doing wrong?

The error occurs when I declare role on the 4th line.

create procedure getRole(in x mediumint unsigned)
begin

DECLARE role INT DEFAULT 3
SELECT user_level INTO role  FROM login_users WHERE user_id = x

        CASE role  
            WHEN 1 THEN  

            WHEN 2 THEN  
                select
                 u.user_level As role,
                 a.id As id,
                 'advisor' As user
                from
                 login_users u
                 inner join login_levels l on u.user_level =l.id
                 inner join rp_adviser a on u.user_id = a.user_id
                where
                 u.user_id = 11;   
            ELSE  
                select
                 u.user_level As role,
                 s.id As id,
                 'student' As user
                from
                 login_users u
                 inner join login_levels l on u.user_level =l.id
                 inner join rp_student s on u.user_id = s.user_id
                where
                 u.user_id = 9;  
                END CASE;  
    end 
  • 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-27T11:50:26+00:00Added an answer on May 27, 2026 at 11:50 am

    Try This :

    DROP PROCEDURE IF EXISTS `getRole` $$
    CREATE PROCEDURE `q1a`.`getRole` (in x mediumint unsigned)
    BEGIN
    
    DECLARE role INT DEFAULT 3;
    SELECT user_level INTO role  FROM login_users WHERE user_id = x;
    
    if(role = 1 or role = 1)
    then
    select
                     u.user_level As role,
                     a.id As id,
                     'advisor' As user
                    from
                     login_users u
                     inner join login_levels l on u.user_level =l.id
                     inner join rp_adviser a on u.user_id = a.user_id
                    where
                     u.user_id = 11;
    else
    select
                     u.user_level As role,
                     s.id As id,
                     'student' As user
                    from
                     login_users u
                     inner join login_levels l on u.user_level =l.id
                     inner join rp_student s on u.user_id = s.user_id
                    where
                     u.user_id = 9;
    end if;
    
    END $$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have a mysql stored procedure which is giving me the following error:- #1064
I have a stored procedure that runs the following: 'ALTER LOGIN ' + @Login
I have a stored procedure that does something like: IF @Param = '1' SELECT
I have the following stored procedure which will generate mon to sun and then
I am using Oracle 10g and I have the following stored procedure: CREATE OR
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,

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.