HELP- How do i create a stored procedure that accepts a user Id and returns the user’s full name and occupation and 1 email address.

Posted on 2016-10-22
Last Modified: 2016-11-11
drop procedure if exists userInformation $$

create procedure userInformation(in uID varchar(50), out fullname varchar(50), out job varchar(50), out email varchar(50))
      select concat(firstname, ' ', lastname) into FULLNAME
      from users
      where userid = uID;
      select occupation into JOB
      from occupation
      join users on users.occupationID = occupation.occupationid
      where userid = uID;
      select useremail into EMAIL from useremail
      join users on useremail.userid = users.userid
      where userid = uID
      limit 1;

delimiter ;
call userInformation('00002380-3e3b-11e3-bbac-c42c03098f6c', @fullnam, @job, @email);
select @fullname, @job, @email;

I get this error when I try and call/select the procedure: Column 'userid' in where clause is ambiguous
Question by:Jim Jones
  • 2
LVL 44

Accepted Solution

AndyAinscow earned 500 total points (awarded by participants)
ID: 41855788
At a guess instead of:
     select occupation into JOB
      from occupation
      join users on users.occupationID = occupation.occupationid
      where userid = uID;

it should be
     select occupation into JOB
      from occupation
      join users on users.occupationID = occupation.occupationid
      where users.userid = uID;

or (less likely based on your names):
     select occupation into JOB
      from occupation
      join users on users.occupationID = occupation.occupationid
      where occupation.userid = uID;

Basically specify which table when the field exists in more than one table
LVL 41

Expert Comment

ID: 41856081
Just a note: You are asking in MS SQL zone but your code seems to have MySQL syntax. Even when the answer is correct for both platforms the code cannot work under MS SQL Server.
LVL 44

Expert Comment

ID: 41883573
The error message was typical for the field existing in two tables - specifying which table is to be used stops the ambiguity

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now