I took the liberty to rewrite your query so it is easier to read.You need to join the skillscard table, otherwise you will get a cross join (cartesian product).Also there is no need to join sc_tc table when you have it in a correlated subquery.( @tc_fk INT, @card_type INT, @card_status INT)ASSET NOCOUNT ONselect distinct TestCentre.tc_pk, TestCentre.brand_name, SkillsCard.name AS sc_name, (select count(*) from sc_tc where sc_tc.tc_fk = tc_pk and sc_tc.sc_fk = skillscard.pk), CASE certificate_sc.candidate_fk WHEN isnull(certificate_sc.candidate_fk, 0) THEN 1 ELSE 2 END AS assignedfrom testcentre, skillscardinner join certificate_sc on certificate_sc.sc_tc_fk = sc_tc.pkwhere (@card_type = -1 or skillscard.type_fk = @card_type) and (@tc_fk is null or testcentre.tc_pk = @tc_fk) and (@card_status is null or (@card_status = 1 and certificate_sc.candidate_fk is not null) or (@card_status = 2 and certificate_sc.candidate_fk is null) )
E 12°55'05.63"N 56°04'39.26"