altmarvel
12-22-2006, 09:53 AM
I'm trying to use two tables in one query, but every time I try this statement, I get an error. Here's what I'm trying to accomplish:
In one query, I want to list the employee number, employee name (last name comma first name), their status (i.e. on leave, active, inactive), and, if active, what department they work in (which is indexed by code).
Here are my tables and examples of the data:
* A = active
* I = inactive
* L = on leave
(department code can only be blank if status is not A)
Employee:
Number | Name | Status | Department_Code
===========================================
0001 | Smith, John | A | AR
0002 | McMurray, Ken | I |
0003 | Jones, Brian | A | AS
0004 | Raymond, Cindy | L |
0005 | Cutter, Jim | A | AR
Departments:
Code | Department
===================
AR | Accounts receivable
AS | Assembly
MG | Upper management
I want to get a listing that looks like this:
0001 | Smith, John | A | AR | Accounts receivable
0002 | McMurray, Ken | I | |
0003 | Jones, Brian | A | AS | Assembly
0004 | Raymond, Cindy | L | |
0005 | Cutter, Jim | A | AR | Accounts receivable
... all in one SQL query. How is this done?
In one query, I want to list the employee number, employee name (last name comma first name), their status (i.e. on leave, active, inactive), and, if active, what department they work in (which is indexed by code).
Here are my tables and examples of the data:
* A = active
* I = inactive
* L = on leave
(department code can only be blank if status is not A)
Employee:
Number | Name | Status | Department_Code
===========================================
0001 | Smith, John | A | AR
0002 | McMurray, Ken | I |
0003 | Jones, Brian | A | AS
0004 | Raymond, Cindy | L |
0005 | Cutter, Jim | A | AR
Departments:
Code | Department
===================
AR | Accounts receivable
AS | Assembly
MG | Upper management
I want to get a listing that looks like this:
0001 | Smith, John | A | AR | Accounts receivable
0002 | McMurray, Ken | I | |
0003 | Jones, Brian | A | AS | Assembly
0004 | Raymond, Cindy | L | |
0005 | Cutter, Jim | A | AR | Accounts receivable
... all in one SQL query. How is this done?