You cant have two where clauses like this in a select statement. probably you need this.alter PROCEDURE [dbo].[spsite]@fromdate datetime,@todate datetimeASBEGINselect site as sitecode, count(case when mydate >=@fromdate and mydate<=@todate then id else null end) as t,count(case when p=1 and mydatestage1 >=@fromdate and mydatestage1<=@todate then id else null end) as p from an where (mydate >=@fromdate and mydate<=@todate)or (p=1 and mydatestage1 >=@fromdate and mydatestage1<=@todate)group by site