select ownerid, fsltablecode ownerType, 'DATA' anomalyType, 'buyingDecisionsDetector' detectorName, companyName + '(' + convert( varchar, operatorId ) + ') is buyingDecisions = N, but oprCompanyType is ' + case when oprCompanyType = '1' then 'Parent' when oprCompanyType = '2' then 'Grand Parent' when oprCompanyType = 'G' then 'GPO' when oprCompanyType = 'C' then 'CMC' else oprCompanyType end as message, 1 anomalyCount from tbl_OPR_ClientOperators where buyingDecisions = 'N' and oprCompanyType in ( '1','G','C' ) and ownerId > 0 order by OwnerID, ownerType, companyName