Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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
3
Medium Priority
?
70 Views
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))
begin
      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;
      
END$$

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
0
Comment
Question by:Jim Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 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
0
 
LVL 43

Expert Comment

by:pcelba
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.
0
 
LVL 44

Expert Comment

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

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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