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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:37:42+00:00 2026-06-05T21:37:42+00:00

I have stored procedure in my database and i need to look up a

  • 0

I have stored procedure in my database and i need to look up a table and cross reference an id, then using the returned row i need to insert information into another table, but i cant seem to use the infomation from the lookup into the insert. This is what i have..

BEGIN
#Routine body goes here...
SET @UID = uid;
SET @UIDTOFB = uid_to;

SET @SQLTEST = CONCAT('SELECT users.user_auto_id FROM users WHERE users.user_fb_uid=     @UIDTOFB LIMIT 1');
PREPARE sqlcmd from @SQLTEST;
EXECUTE sqlcmd;

INSERT INTO challenges(challenge_from_uid, challenge_to_uid, challenge_dateadded) VALUES(@UID, @SQLTEST.users.user_auto_id, now());

SET @LASTID = LAST_INSERT_ID();
SELECT @LASTID as id;

END

any help would be much appreciated!

  • 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-05T21:37:43+00:00Added an answer on June 5, 2026 at 9:37 pm

    This won’t insert the value of @UIDTOFB since you missed some '. It takes this whole statement as one string and therefore the statement fails.

    SET @SQLTEST = CONCAT('SELECT users.user_auto_id FROM users WHERE users.user_fb_uid=     @UIDTOFB LIMIT 1');
    PREPARE sqlcmd from @SQLTEST;
    EXECUTE sqlcmd;
    

    Anyway I’d recommend you use parameters like this:

    PREPARE sqlcmd from 'SELECT users.user_auto_id FROM users WHERE users.user_fb_uid= ? LIMIT 1';
    EXECUTE sqlcmd USING @UIDTOFB;
    

    You can read more about it here in the manual.

    UPDATE: Now I get, what you want to do. Do it simply like this:

    SELECT @anyVariable:=users.user_auto_id FROM users WHERE users.user_fb_uid= @UIDTOFB LIMIT 1;
    INSERT INTO challenges(challenge_from_uid, challenge_to_uid, challenge_dateadded) VALUES(@UID, @anyVariable, now());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure which updates a database using the parameters I supply
I'm using EF database first and have added a stored procedure to the database.
I have a stored procedure called WEB_SEL_SECURITY_QUESTIONS in my sql database which returns a
So I have a stored procedure called Spr_EventLogCreate defined in my database. I have
I have the following PL/SQL stored procedure on an Oracle database: PROCEDURE MyProcedure (
I have the following stored procedure in an SQL Server 2005 database (meant simply
I have a very odd issue. When I execute a specific database stored procedure
We have business restriction in accessing the database only through stored procedure calls. Caching
I need to create mysql stored procedure which makes more than one insert at
I have an access database file (test.mdb) and I need to write a stored

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.