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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:03:12+00:00 2026-05-24T05:03:12+00:00

I am not a MYSQL developer, but just had to write some code. Please

  • 0

I am not a MYSQL developer, but just had to write some code. Please accept my apologies if I am doing anything silly in my code.

My need is to get a single row like select * from users where userID = 1 limit 1 and assign it to a variable and access columns for doing some calculation. Firstly, is this possible?
I have tried to go through step by step, that is why I wrote a simple function like below

    DELIMITER $$

CREATE DEFINER=`user`@`%` FUNCTION `GetReportees`(userid VARCHAR(255)) RETURNS varchar(50) CHARSET latin1
    DETERMINISTIC
BEGIN

    DECLARE Var1 varchar(120);
    DECLARE Var2 varchar(120);
    Select @Var1=forename, @Var2=surname from company_users.users where userID = @userid limit 1;
    return @Var1;
END

when I try to save this function, it says that ERROR 1415: Not allowed to return a result set from a function. But I clearly return a varchar variable.

Could anyone tell me what I am doing wrong? it should not be this much hard, I believe.

Many thanks

Regards

  • 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-24T05:03:12+00:00Added an answer on May 24, 2026 at 5:03 am

    You should read the documentation on the difference between user-defined variables and local variables.

    In your example, you have a parameter and 2 local variables, so you should use them like this:

        DELIMITER $$
    
    CREATE DEFINER=`user`@`%` FUNCTION `GetReportees`(p_userid VARCHAR(255)) 
        RETURNS varchar(120) CHARSET latin1
        DETERMINISTIC
    BEGIN
    
        DECLARE Var1 varchar(120);
        DECLARE Var2 varchar(120);
    
        Select forename, surname 
        into Var1,Var2
        from company_users.users 
        where userID = p_userid 
        limit 1;
    
        return Var1;
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a bad web developer but it happens that I've never had to
I have the same question as #1895500 , but with PostgreSQL not MySQL. How
Any idea why the following code is not working mysql credentials are correct, have
Hi Order By not working on MySql the code is as follows, select *
Ok, I'm not great in mysql, but I know an index would help me
Long time mysql/php user, first time Drupal user. Actually, I'm not doing the Drupal
I need some consultation here. I am a C# developer, and for just about
i've installed mysql connector on my pc. But when i start Visual Web Developer
Why can't the data in mysql not updated when I use checkbox, I already
newthing = Link(user=request.user,last_updated=datetime.datetime.now()) However, this uses datetime , not the MYSQL now(). How can

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.