Question : Struggling with a query!

Hello,

I'm hoping someone can help with the following query problem.
I'm trying to query the 'rota' table to see if any of the following exist in the items column:
Bldg, Room or employee ID.

If the Employee is in the Item column a result should be returned, the same applies if it is his room or building that appears in the item column.

Not quite sure how to set this up as the query keeps telling me I've got a type mismatch.

Any Ideas?

Thanks, Jon

 
table relationships
332157
 

Answer : Struggling with a query!

The query you want looks like this:

Select r.*
from tbl_bldg as x inner join tbl_rota as r on r.item = x.bldgId
union all
Select r.*
from tbl_room as x inner join tbl_rota as r on r.item = cstr(b.RoomId)
union all
Select r.*
from tbl_employee as x inner join tbl_rota as r on r.item = cstr(b.EmployeeId)

HOWEVER, I'm a little reluctant to suggest that query because you are on the slippery slope to a poor database design that you are guaranteed to regret.

It's difficult to advise without knowing what tbl_Rota represents or the business relationship to the other tables, but at a minimum, I advise adding a separate column to reference each of the other 3 tables.  Each of those columns should have an exact matching datatype to the primary key of the corresponding table.







Random Solutions  
 
programming4us programming4us