Try this with coalesce, I think this is a very elegant, clean approach:
SELECT * FROM Customer c WHERE c.StateID=@StateID AND c.CountyID = COALESCE(@CountyID, c.CountyID) AND c.CityID = COALESCE(@CityID, c.CityID)
(Keep in mind - this will filter out records with zeros in CountyID or CityID.)
source share