I have a Master Table and a Detail Table(like Categories and Products) in SQL server and some of the Categories Do not have Products.
I want to count Products of a Category and my Where condition is like this ProductID=100.
In Result i want to have 0 near the Categories that have not Products and the other Categories have Products count. the result must be only for ProductID=100 and the number off the Result is number off the Categories record.iwant to create a view and each time i run this query :
select * from -ViewName where ProductID=@newProductID
This could be done fairly simply in a query that doesn’t use views – it would be something like:
Note that the condition on ProductID has to be part of the join criteria, not in the where clause, otherwise the query will only return categories that include the specified product.
This could be done fairly inefficiently in a view, by using a cross join – something like:
– and then selecting from the view like so: