Sintaxis incorrecta cerca de ')'. SELECT * FROM ( SELECT CURVA,CODMARCA,left(MARCA,21)+'...' as MARCA ,SUM(CANT) AS CANT ,(SELECT top 1 left(DESPROD,21)+'...' FROM dbo.CATALOGO WHERE CURVA = tab.CURVA and IDEMPRESA = tab.IDEMPRESA) as DESPROD ,(SELECT top 1 left(DESPRODCLI,21)+'...' FROM dbo.CATALOGO WHERE CURVA = tab.CURVA and IDEMPRESA = tab.IDEMPRESA) as DESPRODCLI ,left(MAX(ISNULL(CODPRODCLI,CURVA)),21) Descl FROM ( SELECT c.IDEMPRESA,c.CURVA,c.CODPROD,c.CODPRODCLI ,(SELECT CodGrupo FROM SEGURYCELSA.softland.iw_tgrupo WHERE CodGrupo = tp.CodGrupo) as CODMARCA ,(SELECT DesGrupo FROM SEGURYCELSA.softland.iw_tgrupo WHERE CodGrupo = tp.CodGrupo) as MARCA ,isnull((SELECT COUNT(IDDETSOLICITUD) FROM CARROCLIENTE.dbo.DETSOLICITUD WHERE CodProd = c.CODPROD group by CODPROD),0) as CANT FROM dbo.CATALOGO c inner join SEGURYCELSA.softland.iw_tprod tp on c.CODPROD = tp.CodProd WHERE NUMCATALOGO = 1 and IDESTADO = 1 and c.IDEMPRESA = ) tab group by CURVA,CODMARCA,MARCA,IDEMPRESA ) tab2 ORDER BY 4 desc