...
with temp (kennwort, firma1, baustoff, gueltig, ident, norm, download, firmalink, allowce, iconfirmalink) as ( select distinct kennwort, rtrim(firma1) as firma1, rtrim(produkt) as baustoff, CONVERT(varchar(15), gueltigab, 106) as 'gueltig', Identifikationsnummer as 'ident', '' + rtrim(Bezugsnorm) + '
' + rtrim(Produkttyp) + '
' as 'norm', download, firmalink, allowce, iconfirmalink from firmen.dbo.view_produktfrei2023 where ((compcode='' or kennwort='') and len('')=6 and ((prodid='' or jubaproductid='') and len('')>=1)) or ((lfart='§§§§§' or ean='§§§§§' or Identifikationsnummer='§§§§§' or produkt='§§§§§' /* like '%'+'§§§§§'+'%' */ ) and '§§§§§'<>'§§§§§' /* and len('')=0 */)) select top 12 iif(len('eis3')=6, firmalink, iif(left('', 2)='AT', iconfirmalink, baustoff)) +'
'+firma1+'' as Produkt, download as Download, gueltig as 'Datum ab', ' '+iif(allowce=0, '-', '+')+' ' as 'CE ',ident as Ident, norm as Norm, ROW_NUMBER() OVER(ORDER BY firma1, baustoff, gueltig DESC) AS '#' from temp order by 7