select '{"Logic":"-", "Field":"LogText", "Comp":"~", "Value":"/^' + replace(replace(replace(replace(replace(replace(replace(TXT ,'%1','.*'),'%2','.*'),'%3','.*'),'%4','.*'),'%5','.*'),'%6','.*'),'%7','.*') + '/"},' from ( select replace(replace(replace(replace(replace(replace(TXT,'"','\"'),'(','\\('),')','\\)'),'.','\\.'),'*','\\*'),'+','\\+') "TXT" from ( select CASE WHEN CHARINDEX(char(10),TXT)=0 THEN txt ELSE SUBSTRING(TXT,0,CHARINDEX(char(10),TXT)-1) END "TXT" from ( select distinct convert(nvarchar(max),text) TXT from RpsMessageText where status != 'd' and language != 'de' and rpsmessagepkey not in (select pkey from rpsmessage where CodePrefix in( 'ANA','ASP','BWI','GRI','PDA','STR','RPS','TPO','SVC','PLN') or id like '%Char' ) ) a where txt not like 'Validation notification%' and txt not like 'Validiation notification%' and txt not like 'Notificação de validação%' and txt not like '¡Alerta de Validación!%' ) b ) c Where len(convert(varchar(max),TXT)) > 10 /* anything shorter than 10 will be some sort of label or so.*/