SQLTeam.com | Weblogs | Forums

Sql reusable query based on the conditions

the following query based on the condition (isFiltered) is not working, please provide solution regarding this. Thanks in advance

insert into @Ids values ( ( 78443 ) );

select count(*) as TotalCount from pat pa join patRel por on pa.id = por.id join organi org on por.OrganisationId = case @IsFiltered when 1 then (select value from @Ids) else org.OrganisationId end where pa.regID = 10 and pa.TypeId = @PatientTypeId and pa.SubtypeId = @PatientSubtypeId

select count(*) as TotalCount, case @IsFiltered when 1 then (select value from @Ids) else org.OrganisationId end from
pat pa join patRel por on pa.id = por.id join organi org on por.OrganisationId = org.OrganisationId
where pa.regID = 10 and pa.TypeId = @PatientTypeId and pa.SubtypeId = @PatientSubtypeId