i have a Relation from N to N from categories to Items in my database.
I have three tables for this:
Categories, Items and Categories_Items
I would like to get all the categories and an extra field beside each one telling me if is active or not.
This is what i have by the moment:
SELECT C.ID
,C.Name
,IsActive=????
FROM Categories C
left join Items_Categories IC on IC.CategoryID=C.ID
where IC.ItemId=@ItemID
The result i would like to get is a list of all the available categories and marked as active those that are in the table Items_Categories and matches with the @ItemId:
ID Name IsActive -- --------- -------- 1 Category1 0 2 Category2 1 3 Category3 .....
Try this: