Jump to content
Fórum Script Brasil
  • 0

Consulta com Union - Só para Experts


Henriquegm

Question

Quando executo esta consulta, a mesma retorna, TIPO DE DADOS INCOMPATÍVEL NA EXPRESSÃO DE CRITÉRIO.

Se eu retiro qualquer umas das três consultas, funciona.

Onde estou errando?

segue a consulta:

===================================================================

select BICO, DATA, VALOR, ENC_INI, ENC_FIM, AFER, LITROS

from [

SELECT

a.COD_BICO AS BICO,

b.DTA_FECHAMENTO AS DATA,

Null AS VALOR,

a.NUM_ENCERRANTE_INICIAL AS ENC_INI,

Null AS ENC_FIM,

Null AS AFER,

Null AS LITROS

FROM tab_medicao_bico AS a INNER JOIN tab_fechamento_caixa_pdv AS b ON a.SEQ_FECHAMENTO = b.SEQ_FECHAMENTO

WHERE

(((a.COD_BICO)>3)

AND ((b.DTA_FECHAMENTO)=#11/12/2010#)

AND ((b.NUM_FECHAMENTO)=1))

UNION ALL

SELECT

a.COD_BICO AS BICO,

b.DTA_FECHAMENTO AS DATA,

Sum(a.VAL_LIQUIDO) AS VALOR,

Null AS ENC_INI,

Null AS ENC_FIM,

Sum(a.QTD_AFERICAO) AS AFER,

Sum(a.NUM_ENCERRANTE_FINAL-a.NUM_ENCERRANTE_INICIAL) AS LITROS

FROM tab_medicao_bico AS a INNER JOIN tab_fechamento_caixa_pdv AS b ON a.SEQ_FECHAMENTO = b.SEQ_FECHAMENTO

GROUP BY a.COD_BICO, b.DTA_FECHAMENTO

HAVING

(((a.COD_BICO)>3)

AND ((b.DTA_FECHAMENTO)=#11/12/2010#))

UNION ALL

SELECT

a.COD_BICO AS BICO,

b.DTA_FECHAMENTO AS DATA,

Null AS VALOR,

Null AS ENC_INI,

a.NUM_ENCERRANTE_FINAL AS ENC_FIM,

Null AS AFER,

Null AS LITROS

FROM tab_medicao_bico AS a INNER JOIN tab_fechamento_caixa_pdv AS b ON a.SEQ_FECHAMENTO = b.SEQ_FECHAMENTO

WHERE

(((a.COD_BICO)>3)

AND ((b.DTA_FECHAMENTO)=#11/12/2010#)

AND ((b.NUM_FECHAMENTO)=3))

]. as LMC

ORDER BY BICO, DATA

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...