Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column lookup getting in way

Status
Not open for further replies.

JFoushee

Programmer
Joined
Oct 23, 2000
Messages
200
Location
US
Hi... building a query to demonstrate orphaned/missing records.

In this case, all employees should be assigned an active position.

So I have a query that will show all employees who have bogus (missing) positions....

Code:
SELECT PersonnelID, Name, PositionID
FROM tblPersonnel
WHERE PositionID NOT IN (SELECT PositionID FROM tblPositions)
AND PositionID <> 0
ORDER BY PersonnelID
But I get back results....
Code:
_______________________________________________
| PersonnelID | Name            | Position     |
|-------------|-----------------|--------------|
|          60 | John Doe        |              |
|         231 | Jane Doe        |              |
|         286 | And so on...    |              |
|-------------|-----------------|--------------|

I explicitly asked for the PositionID, but because of a Lookup function behind the column, I get this goofy blank pulldown.

Is there a way to show the behind-the-scenes ID?
Code:
_______________________________________________
| PersonnelID | Name            | PositionID   |
|-------------|-----------------|--------------|
|          60 | John Doe        |           83 |
|         231 | Jane Doe        |          125 |
|         286 | And so on...    |          125 |
|-------------|-----------------|--------------|
 
Nevermind, I did this:
Code:
SELECT ... PositionID + 0
 
looks like those are nulls....why not just:
Code:
SELECT PersonnelID, Name, PositionID
FROM tblPersonnel H
LEFT OUTER JOIN tblPosition P on H.PositionID = P.PositionID
WHERE H.PositionID <> 0
ORDER BY PersonnelID

check out Understanding SQL Joins

Leslie

Have you met Hardy Heron?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top