TSQL Help

  • Looking at the ERD there is a many:many relationship between Category and Department (i.e. the same department can appear in many categories - hence the bridging table DepartmentCategory)

    A product is linked to its category via the CarModel but there is no direct relationship for the product to department. Effectively your relationship rules expose the product to every department that is linked to the category so the category ID on the WHERE clause is redundant.
    You need to find a way to directly associate CarModel with Department.  Either a Department ID on CarModel or make Department a 1:many relationship with category (i.e. a sub-category)
    Alternatively try modifying the first part of the WHERE clause to use DepartmentCategory.CategoryID = @CategoryID.

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply