How to get main responsible staff name when a selected staff shared equipment withhim

jp2468

Registered User.
Local time
Today, 18:47
Joined
Sep 30, 2010
Messages
17
Hi,

I have two tables as the below:
Equipment: EquipmentID (Auto Number), Equipment Name, Purchased Date.
Shared : Category(primary, Secondary), StaffName, Department, Assigned Date, and EquipmentID(as foreign key)

One Equipment may have couple of staffs shared with it as the below I explained:

EquipmentID; EquipmentName; PurchasedDate
1; Main Printer ; 1/1/2010.


Category; staffName; Department; AssignedDate; EquipmentID.
Primary; Jeff Word; IT; 1/1/2010; 1
Secondary; Mary Little; Marketing; 2/1/2010; 1
Secondary; Lisa Holt; Data Entry; 1/1/2010; 1
Primary; Bob Big; Tech; 2/3/2010; 1


Staff with Primary means this staff is responsible for maintaining this equipment.

Staff with Secondary means this staff shared equipment, but don’t need to do any maintenance job. The report will search or sorted by a staff name. if I search Mary Little, the data under the report will show her as a Secondary staff. In that case, I also want to see who is/are primary staff(s) shared equipment with Mary.

Can I do that in a query, something like below:

SELECT tbl_Equipment.EquipmentName, tbl_Equipment.PurchasedDate, Shared.Staffname, Shared.Department, Shared.Category,
Case
When (Shared.Category) = 'Secondary' then (select Shared.Sname
from Shared
where Shared.Category = 'Primary')
else ' '
End as SharedStaff
FROM tbl_Equipment INNER JOIN Shared ON tbl_Equipment.ID = Shared.ID
ORDER BY tbl_Equipment EquipmentName;

Anyone can help, and tell me how to do that?

Thank you very much for your time and help.
 
Last edited:
I'd suggest adjusting your tables and getting some Normalized structures with relationships

Equipment
Person
AssignedEquipment
Department

A Person works in one Department
Equipment can be Assigned to one or more Persons
On a shared AssignedEquipment one Person is identified as Primary
Equipment is Assigned for a specified period of time
etc.
etc.
 
Hi, Jdraw,
Thanks for reply my question.
Even I separate tables like you suggested, When I search a staff name, who is secondary in the AssignedEquipment table, how can I also get a additional field to show who is Primary staff shared with him/her too?
Thanks again.
 
Please show the SQL of your query and we'll try to help.
 

Users who are viewing this thread

Back
Top Bottom