473,471 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Beginner question, stored procedure

Hello,

I have 2 tables: Employees(EmployeeID, FirstName, LastName),
EmployeeApplication(CreatedByID, EmployeeID,Date1, Date2, Content...)
I need to create stored procedure that will return employee First and
Last names (plus some other columns) instead *both* ID's in
EmployeeApplication.
I know how to do it with only one - I am using simple join, but with
two I have no idea...
Can anyone help me ?

Richard...
Nov 18 '07 #1
1 1322
Hi Richard,

You simply add one more join for the Employees table to get the names for
the other ID, something like this:

SELECT A.EmployeeID,
E.FirstName AS emp_fname,
E.LastName AS emp_lname,
A.CreatedByID,
C.FirstName AS creator_fname,
C.LastName AS creator_lname,
A.Date1,
A.Date2,
A.Content
FROM EmployeeApplication AS A
JOIN Employees AS E
ON A.EmployeeID = E.EmployeeID
JOIN Employees AS C
ON A.CreatedByID = C.EmployeeID

This is assuming the CreatedByID column is referring to the EmployeeID
column from the Employees table. If that is not the case then you have to
replace the Employees table in the second join with the appropriate table
and the appropriate column for the join.

HTH,

Plamen Ratchev
http://www.SQLStudio.com
Nov 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Francisco Williams | last post by:
Hi, I searched through this newsgroup looking for an answer for this, but didn't find any (it probably is here. Just didn't find it). I am trying to retrieve information from two related tables,...
5
by: Eric Herber | last post by:
I've a question regarding DB2 SQL Stored Procedures (DB2 V8.1.4 on Suse Linux). It seems not to be possible to use the 'where current of <cursor>' syntax in conjunction with dynamically prepared...
1
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME,...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
3
by: Ken H | last post by:
Hi I have a question about architecting solutions.. I have a part of a project which requires me to track person details (name, addresses, etc... Should I be creating Person objects, Address...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
6
by: jrpfinch | last post by:
I have a table with two columns: siteID (int primary key) and siteName (varchar(50) unique constraint). I am completely new to databases and UDFs and would like to write a function that looks...
9
by: Mike Hofer | last post by:
In a large application I'm working on (ASP.NET 1.1, VS2003), we have a base class that wraps stored procedures. Essentially, this base class (StoredProcedureBase) encapsulates the code to set up...
5
by: william.david.anderson | last post by:
Hi there, I have a newbie question regarding stored procedures and locking. I'm trying to use a stored procedure to perform a 'select for update' and return a cursor. Below is a stripped down...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.