select ProductId,Product,sum(Counter) as Counter
from
V_OneSettlementForQuarterByProduct
where
convert(STR_TO_DATE(DATE_FORMAT(`datetime`,'%M%D%Y'),'%M%D%Y'),convert(varchar(10),AuthDate,101),102) >= convert(STR_TO_DATE(DATE_FORMAT(`datetime`,'%M%D%Y'),'%M%D%Y'),convert(varchar(10),?,101),102)
and convert(STR_TO_DATE(DATE_FORMAT(`datetime`,'%M%D%Y'),'%M%D%Y'),convert(varchar(10),AuthDate,101),102) <= convert(STR_TO_DATE(DATE_FORMAT(`datetime`,'%M%D%Y'),'%M%D%Y'),convert(varchar(10),?,101),102)
and ProductId =?
group by ProductId,Product
order by ProductId