declare @counts int = 0
set @counts = (SELECT count(pd.IsSerialNumberMaskRequired) from ProductSetup.ProductVersion as pv
INNER join ProductSetup.ProductDetail as pd
on pv.ProductHeaderId = pd.ProductHeaderId
where pv.ProductVersionId = '24127' and pd.IsSerialNumberMaskRequired = 1
group by pd.IsSerialNumberMaskRequired)
IF @counts > 0
select 1