Ver Mensaje Individual
  #1  
Antiguo 12-05-2006
Avatar de apicito
apicito apicito is offline
Miembro
 
Registrado: may 2003
Ubicación: Ourense
Posts: 341
Reputación: 24
apicito Va por buen camino
Problema con group by

Porqué si a esta consulta:
Código Delphi [-]
      SQL.Add('select A.SESASU_GRUPO,A.SESASU_ASUNTO as ASUNTO');
      SQL.Add('from SES'+Part+'ASU A join SES'+Part+'GRU G on G.SESGRU_CODIGO=A.SESASU_GRUPO');
      Sql.Add('where G.SESGRU_MOSTRAR=1');
      SQL.Add('and A.SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
      SQL.Add('union');
      if Datos.CargaIni('Servidor','SOperativo')='Linux' then
        SQL.Add('select A.SESASU_GRUPO,string2blob(G.SESGRU_DESCRIP) as ASUNTO')
      else
        SQL.Add('select A.SESASU_GRUPO,F_STRBLOB(G.SESGRU_DESCRIP) as ASUNTO');
      SQL.Add('from SES'+Part+'ASU A join SES'+Part+'GRU G on G.SESGRU_CODIGO=A.SESASU_GRUPO');
      Sql.Add('where G.SESGRU_MOSTRAR=0');
      SQL.Add('and A.SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
      Sql.Add('group by A.SESASU_GRUPO,G.SESGRU_DESCRIP');
le añado en los select el campo A.SESASU_NUMERO que es un contador dentro del grupo (A.SESASU_GRUPO) de esta forma:
Código Delphi [-]
      SQL.Add('select A.SESASU_GRUPO,A.SESASU_ASUNTO as ASUNTO,A.SESASU_NUMERO');
      SQL.Add('from SES'+Part+'ASU A join SES'+Part+'GRU G on G.SESGRU_CODIGO=A.SESASU_GRUPO');
      Sql.Add('where G.SESGRU_MOSTRAR=1');
      SQL.Add('and A.SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
      SQL.Add('union');
      if Datos.CargaIni('Servidor','SOperativo')='Linux' then
        SQL.Add('select A.SESASU_GRUPO,string2blob(G.SESGRU_DESCRIP) as ASUNTO,A.SESASU_NUMERO')
      else
        SQL.Add('select A.SESASU_GRUPO,F_STRBLOB(G.SESGRU_DESCRIP) as ASUNTO,A.SESASU_NUMERO');
      SQL.Add('from SES'+Part+'ASU A join SES'+Part+'GRU G on G.SESGRU_CODIGO=A.SESASU_GRUPO');
      Sql.Add('where G.SESGRU_MOSTRAR=0');
      SQL.Add('and A.SESASU_SESION='+#39+inttostr(SesCodigo)+#39);
      Sql.Add('group by A.SESASU_GRUPO,G.SESGRU_DESCRIP');
me da error de :
Invalid expression in the Select list (not contained in either an aggregate function or the GROUP BY clause).
Responder Con Cita