Subject Problem in very long query....
Author Sergio Lenzi
Hello all...

That is me with the query error again...

Now the situation is becoming more clear...

I got the whole statement (sql) from the application program...
it is a very huge one... about 4820 characters...
and... yes they have not sent me the complete stm....

The strange situation is that when I type the statement in the isql
it works....

I am sending you the sql command used to generate the result...

The application program uses ibexpert access method to send it to the
firebird...
and the program does:
add ('xxxx');
add ('xxxx');
add ('xxxxx');
add ('commit;')
sendquery();

delphi 6..

Firebird working on FreeBSD version 1.5rc7 running on inetd (not
superserver...)

Is there a way to log the queries in the firebird server???
this would show me what is going on in the firebird engine...

Any ideas????



SELECT PCABVDA.EMPRESA, PCABVDA.NROVDA, PPESCLI.NOME,
PPESCLI.CLIENTE, PCABVDA.DTEMISSAO, PSTRIS.ORIGEM,
PCUPOM.SITUACAO, PREPRESE.DESCRICAO,
PCABVDA.APARTIRVDA, PCABVDA.NRONF,
PCABVDA.CONSFINAL,
NVLF(PCABVDA.VLRSEGURO,0) AS VLRSEGURO,
NVLF(PCABVDA.VLRFRETE,0) AS VLRFRETE,
NVLF(PCABVDA.ACRESCIMOS,0) AS ACRESCIMOS,
NVLF(PCABVDA.DESCONTOS,0) AS DESCONTOS,
NVLF(SUM(PESTOQUE.TOTAL),0) AS SomaDeTOTAL,
NVLF(SUM(DIVIDE((PITEVDA.BASEIPI*PITEVDA.ALIQIPI),100)),0) AS
VLRIPI,
NVLF(SUM(PSTRIS.ICMSST),0) AS SomaDeICMSST,
PNATUOPE.CONSDEMOLP, NVLF0(0) AS TOTALSERVICOS
FROM PCABVDA
LEFT JOIN PNATUOPE
ON (PCABVDA.NATUREZA = PNATUOPE.NATUREZA)
LEFT JOIN PREPRESE
ON (PCABVDA.EMPRESA = PREPRESE.EMPRESA)
AND (PCABVDA.REPRESENT = PREPRESE.REPRESENT)
LEFT JOIN PPESCLI
ON (PCABVDA.EMPRESA = PPESCLI.EMPRESA)
AND (PCABVDA.CLIENTE = PPESCLI.CLIENTE)
LEFT JOIN PITEVDA
ON (PCABVDA.EMPRESA = PITEVDA.EMPRESA)
AND (PCABVDA.NROVDA = PITEVDA.NROVDA)
LEFT JOIN PESTOQUE PESTOQUE_VDA
ON (PITEVDA.EMPRESA = PESTOQUE.EMPRESA)
AND (PITEVDA.ITEM = PESTOQUE.ITEM)
AND (PITEVDA.DATA = PESTOQUE.DATA)
AND (PITEVDA.SEQUENCIA = PESTOQUE.SEQUENCIA)
LEFT JOIN PITENS
ON (PITEVDA.EMPRESA = PITENS.EMPRESA)
AND (PITEVDA.ITEM = PITENS.ITEM)
LEFT JOIN PSTRIS
ON (PITEVDA.EMPRESA = PSTRIS.EMPRESA)
AND (PITEVDA.NROVDA = PSTRIS.NRODOCTO)
AND (PITEVDA.ITEM = PSTRIS.ITEM)
AND (PITEVDA.SEQITEVDA = PSTRIS.SEQITE)
LEFT JOIN PCUPOM
ON (PCABVDA.EMPRESA = PCUPOM.EMPRESA)
AND (PCABVDA.NROVDA = PCUPOM.NROVDA)
WHERE (PCABVDA.EMPRESA = 1001 )
AND (PCABVDA.DTEMISSAO >= '09-01-2003')
AND (PCABVDA.DTEMISSAO <= '12-16-2003')
AND (PPESCLI.NOME COLLATE PT_PT >= 'A')
AND (PPESCLI.NOME COLLATE PT_PT <= 'C')
AND ((PCUPOM.SITUACAO = 'I')
OR (PCUPOM.SITUACAO IS NULL))
AND ((PSTRIS.ORIGEM = 5)
OR (PSTRIS.ORIGEM IS NULL))
GROUP BY PCABVDA.EMPRESA, PCABVDA.NROVDA, PPESCLI.NOME,
PPESCLI.CLIENTE, PCABVDA.DTEMISSAO, PSTRIS.ORIGEM,
PCUPOM.SITUACAO, PREPRESE.DESCRICAO, PCABVDA.VLRSEGURO,
PCABVDA.VLRFRETE, PCABVDA.ACRESCIMOS, PCABVDA.DESCONTOS,
PCABVDA.CONSFINAL, PCABVDA.APARTIRVDA, PCABVDA.NRONF,
PNATUOPE.CONSDEMOLP
UNION
SELECT
PCABVDA.EMPRESA, PCABVDA.NROVDA, PPESCLI.NOME,
PPESCLI.CLIENTE, PCABVDA.DTEMISSAO, 0 AS ORIGEM,
PCUPOM.SITUACAO, PREPRESE.DESCRICAO,
PCABVDA.APARTIRVDA, PCABVDA.NRONF,
PCABVDA.CONSFINAL,
NVLF(PCABCOMP.VLRSEGURO,0)*-1 AS VLRSEGURO,
NVLF(PCABCOMP.VLRFRETE,0)*-1 AS VLRFRETE,
NVLF(PCABCOMP.ACRESCIMO,0)*-1 AS ACRESCIMOS,
NVLF(PCABCOMP.DESCONTO,0)*-1 AS DESCONTOS,
NVLF(SUM(PESTOQUE.TOTAL),0)*-1 AS SomaDeTOTAL,
NVLF(SUM(DIVIDE((PITECOMP.BASEIPI*PITECOMP.ALIQIPI),100)),0)*-1 AS VLRIPI,
NVLF(SUM(0),0) AS SomaDeICMSST,
PNATUOPE.CONSDEMOLP, NVLF0(0) AS TOTALSERVICOS
FROM PCABCOMP
LEFT JOIN PITECOMP PITECOMP_CMP
ON (PITECOMP.EMPRESA = PCABCOMP.EMPRESA)
AND (PITECOMP.NROCOMPRA = PCABCOMP.NROCOMPRA)
LEFT JOIN PESTOQUE PESTOQUE_CMP
ON (PESTOQUE.EMPRESA = PITECOMP.EMPRESA)
AND (PESTOQUE.ITEM = PITECOMP.ITEM)
AND (PESTOQUE.DATA = PITECOMP.DATA)
AND (PESTOQUE.SEQUENCIA = PITECOMP.SEQUENCIA)
LEFT JOIN VPDEVVDA
ON ( VPDEVVDA.EMPRESA = PCABCOMP.EMPRESA)
AND( VPDEVVDA.NROCOMPRA = PCABCOMP.NROCOMPRA)
LEFT JOIN PCABVDA
ON ( PCABVDA.EMPRESA = VPDEVVDA.EMPRESA )
AND ( PCABVDA.NROVDA = VPDEVVDA.NROVDA )
LEFT JOIN PNATUOPE
ON (PCABVDA.NATUREZA = PNATUOPE.NATUREZA)
LEFT JOIN PREPRESE
ON (PCABVDA.EMPRESA = PREPRESE.EMPRESA)
AND (PCABVDA.REPRESENT = PREPRESE.REPRESENT)
LEFT JOIN PPESCLI
ON (PCABVDA.EMPRESA = PPESCLI.EMPRESA)
AND (PCABVDA.CLIENTE = PPESCLI.CLIENTE)
LEFT JOIN PCUPOM
ON (PCABVDA.EMPRESA = PCUPOM.EMPRESA)
AND (PCABVDA.NROVDA = PCUPOM.NROVDA)
WHERE (PCABVDA.EMPRESA = 1001)
AND (PCABVDA.DTEMISSAO >= '09-01-2003')
AND (PCABVDA.DTEMISSAO <= '12-16-2003')
AND (PPESCLI.NOME COLLATE PT_PT >= 'A')
AND (PPESCLI.NOME COLLATE PT_PT <= 'C')
AND ((PCUPOM.SITUACAO = 'I') OR (PCUPOM.SITUACAO IS NULL))
GROUP BY PCABVDA.EMPRESA, PCABVDA.NROVDA, PPESCLI.NOME,
PPESCLI.CLIENTE, PCABVDA.DTEMISSAO,PCUPOM.SITUACAO,
PREPRESE.DESCRICAO,PCABVDA.CONSFINAL, PCABVDA.APARTIRVDA,
PCABVDA.NRONF, PNATUOPE.CONSDEMOLP,
PCABCOMP.VLRSEGURO,PCABCOMP.VLRFRETE,
PCABCOMP.ACRESCIMO, PCABCOMP.DESCONTO;