Query to show whether certain types of things are assigned to a person

Anonymous
2025-06-18T18:58:04+00:00

Howdy.

I have

tblItems - ItemID pk, ItemTypeID fk (what kind of item it is), EmployeeID fk (If it's assigned to an employee, will have their EmployeeID, null if not assigned)

What I was trying to do is get a query to have one column the EmployeeID, then a column for 5 different specific item types and have that just be a True/False whether that person has that item.

EmployeeID ItemTypeA ItemTypeB ItemTypeC ItemTypeD ItemTypeE
1 0 -1 -1 0 0
2 -1 -1 0 0 0
3 0 0 -1 -1 -1

I can get a query where it has the EmployeeID multiple times, and each row has one true value, and the rest false. But not one condensed thing. Is this possible?

The reason for this is I've got a list of jobs that have whether or not that job requires certain item types assigned to them, and I'm setting up a transfer system where if a person changes jobs it will say whether or not they need to have an item assigned to them, if no change is needed, or if they need an item taken from them so it can be put back into the pool to be assigned to someone else in the future.

Microsoft 365 and Office | Access | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. George Hepworth 21,805 Reputation points Volunteer Moderator
    2025-06-18T19:06:55+00:00

    The underlying problem is an inappropriate table design.

    The user of aliases for the real field names helps expose this problem:

    ItemTypeA ItemTypeB ItemTypeC ItemTypeD ItemTypeE

    Whenever you see this pattern of "Something" + a counter, that's a sign the original data was either in Excel or a table created without considering good relational table design.

    So, the solution is to Normalize this table properly so that the query becomes simple and direct.

    Actually, you need three tables here:

    Employees

    Items

    EmployeeItemAssignments

    Employees needs its Primary Key, such as EmployeeID.

    Items needs its Primary Key, such as ItemID.

    In the third table, you have one record for each employee and Item combination.

    If an employee is assigned one item, there will be only one record for that employee-item assignment.

    If an employee is assigned two items, there will be two records for that employee with the two item assignments.

    These assignments are designated by including the appropriate EmployeeID and the appropriate ItemID for each assignment.

    Additional fields could include the date the assignment was made and the date it ended, if that's relevant to your business model.

    That's a narrative explanation. For a deeper background, I suggest investing time in researching Database Normalization. Look for Many-to-Many relationships and how they are handled properly.

    I expect you'll receive additional, more technically detailed responses, as well.

    The key point is that improper, or non-normalized tables make for rough sledding when you need to query them.

    0 comments No comments
  2. Anonymous
    2025-06-18T19:23:46+00:00

    I just want to clarify to make sure my information got across before changing how my database is built.

    The ItemTypeA stuff was just an example of what I was hoping to see from the query. Below is a mockup of the table data itself.

    It's not just whether an employee is assigned an item, it's whether they are assigned a particular type of item. For these purposes if they've been assigned one, two, or ten doesn't matter. Hence why I was just trying for a True/False field with the name of the item (ItemTypeA as a substitute for the actual type name) as the column name.

    ItemID ItemTypeID EmployeeID
    351 2
    451 2 21
    490 3 21
    590 4 12
    690 2 12
    0 comments No comments
  3. Anonymous
    2025-06-18T20:51:21+00:00

    To return a result table as you've described a crosstab query would be used.  For an example take a look at DatabaseBasics.zip in my Dropbox public databases folder at:

    https://www.dropbox.com/scl/fo/0scigd3r48hx5xrev2jrf/AB0-GMdTgMAO5O1cGdr3QW0?rlkey=ib6bs6g9jqcrywwzivur3265t&dl=0

    In this little demo file the following section illustrates a crosstab query. 

    18. Returning rows with data as column headings by means of a crosstab query

    If amended as follows, rather than returning the total amounts at the intersections of the column and row headings, the query would return TRUE, expressed as -1, in place of the currency values returned in the demo:

    TRANSFORM IIF(COUNT(*)>0,TRUE,FALSE)

    SELECT FirstName, LastName, SUM(TransactionAmount) AS TotalAmount

    FROM Customers RIGHT JOIN (Calendar LEFT JOIN Transactions

    ON Calendar.calDate = Transactions.TransactionDate)

    ON Customers.CustomerID = Transactions.CustomerID

    WHERE YEAR(calDate) = 2009 AND MONTH(calDate) = 4

    GROUP BY FirstName, LastName

    PIVOT calDate;

    Because of the OUTER JOINs the above would  return a specious row with zero length strings at the  FirstName and LastName column positions.  This can be removed by a further query as in the demo.

    1 person found this answer helpful.
    0 comments No comments
  4. George Hepworth 21,805 Reputation points Volunteer Moderator
    2025-06-18T22:05:56+00:00

    Ah, I see. You showed the "after" not the "before". Sorry.

    A crosstab will work, as Ken detailed for you.

    0 comments No comments
  5. Anonymous
    2025-06-19T08:30:49+00:00

    Thank you very much for the help. And thank you George as well, and I apologize for not being clearer in my initial post.

    0 comments No comments