Jump to content
Fórum Script Brasil
  • 0

(Resolvido) ERRO SUB-QUERY


Vinicius Schuh

Question

Boa tarde pessoal

tenho o seguinte SQL:

SELECT     
dbo.tblOrdens_servico.ID As OS, 
dbo.tblOrdens_servico.CD_Cliente,
dbo.Clientes.NomeDoCliente, 
dbo.tblOrdens_servico.CD_Tecnico,
dbo.Funcionários.NomeDoFuncionário, 
dbo.tblOrdens_servico.DT_Os As Abertura, 
dbo.tblOrdens_servico.DT_Fechamento As Fechamento, 
DATEDIFF(Day, dbo.tblOrdens_servico.DT_Os, dbo.tblOrdens_servico.DT_Fechamento) As Total_Dias, 

(Select DATEDIFF(Day, DT_Os, GetDate())from dbo.tblOrdens_Servico where TP_Aberta = 1) As Aberto_Dias, 

OS_Status = Case When (dbo.tblOrdens_Servico.TP_Aberta = 1) Then 'ABE'  When (dbo.tblOrdens_Servico.TP_Andamento = 1) Then 'AND' When (dbo.tblOrdens_Servico.TP_Concluida = 1) Then 'FEC' End,
dbo.tblOrdens_Servico.TP_Aberta,
dbo.tblOrdens_Servico.TP_Andamento,
dbo.tblOrdens_Servico.TP_Concluida  
FROM
dbo.Clientes 
LEFT JOIN
dbo.tblOrdens_servico On dbo.Clientes.CódigoDoCliente = dbo.tblOrdens_servico.CD_Cliente 
LEFT JOIN
dbo.Funcionários On dbo.tblOrdens_servico.CD_Tecnico = dbo.Funcionários.CódigoDoFuncionário
WHERE
(dbo.Funcionários.NomeDoFuncionário Is Not Null)

Se eu executo minha query, ela me retorna o seguinte erro:

Msg 512, Level 16, State 1, Line 2

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

(0 row(s) affected)

Mas, se eu removo a sub-query ele roda sem problemas ou se eu executo apenas a sub-query ele também roda.

O que deixei passar para que não esteja rodando a query+sub-query?

abraço

Edited by Vinicius Schuh
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Bom dia Fulvio, resolvi hehe. Mudei a parametrização da minha função DATEDIFF e fiz as verificações dos dias, que ficou dessa forma:

DATEDIFF(Day, dbo.tblOrdens_servico.DT_Os, Case When (dbo.tblOrdens_servico.TP_Concluida = 1) then  dbo.tblOrdens_servico.DT_Fechamento Else  getdate() End) As Total_Dias,

Abraços...

Link to comment
Share on other sites

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...