So I'm trying to get a where statement in a select to work instead of using a large amount of if statements... I ALMOST have my head wrapped around it but I just can't get it that extra bit to make it all work.What I have...Declare @ProvinceID int, @CityID int, @EventTypeID intSet @ProvinceID = 7Set @CityID = 0Set @EventTypeID = 38select * from Eventswhere ((EventTypeID=@EventTypeID or ProvinceID=@ProvinceID or CityID=@CityID)-- This covers just 1 of the variables being filled but also causes issues if 2 or 3 are filledor((EventTypeID=@EventTypeID and CityID=@CityID) or (EventTypeID=@EventTypeID and ProvinceID=@ProvinceID)-- Covers if 2 are filled but breaks if all 3 are filled and won't work anyways as the first part of the where has or but if I add and it won't work with 1 variable) or((EventTypeID=@EventTypeID and CityID=@CityID) and (EventTypeID=@EventTypeID and ProvinceID=@ProvinceID)-- Covers all 3 being filled. ) )
Since the 3 variables can be separate or intermixed it would be a tonne of ugly looking ifs or just a bit of brain power and a somewhat ugly where.Anyone care to help me get over this hump?