How to put ISNULL in Subselect with case?

0

How do I instead return Null return as Não . I'm in doubt about using ISNULL within Subselect along with the case.

Result:

Projeto teste     Null

Projeto OK        Sim.

Instead of Null want to return NÃO , how do I?

SELECT DISTINCT concat(CC.Descricao,'-',U1.UsuNome),
                C.CompDesc QtdeCNPJs,

  (SELECT top 1 Faturado = CASE T1.TarEstagioID
                               WHEN 112 THEN 'SIM'
                               ELSE 'NÃO'
                           END
   FROM Projetos P
   INNER JOIN Tarefa T1 ON P.ProjID = T1.ProjID
   WHERE T1.TarStatus = 9
     AND T1.TarTitulo = 'Treinamento Realizado - Emitir Boleto Setup'
     AND P.ProjID = PP.ProjID
     AND T1.TarTipID = 674) Faturado
FROM PROJETOS PP
INNER JOIN Tarefa T ON PP.ProjID = T.ProjID
INNER JOIN Usuario U ON T.UsuIDResponsavel = U.UsuID
INNER JOIN Usuario U1 ON T.UsuIDCliente = U1.UsuID
LEFT JOIN Complemento C ON C.UsuID = T.UsuIDCliente
AND C.CompID = 1
LEFT JOIN CurvaABC CC ON (CC.CurvaID = U1.CurvaID)
WHERE CC.CurvaID = 1
    
asked by anonymous 26.07.2017 / 16:23

2 answers

-1

Renan,

I used the ISNULL function of sqlServer.

Example:

SELECT ISNULL(STATUS, 0) AS STATUS FROM T_TESTE

In this situation, if the status field comes nullo it will be replaced by 0.

If you can not, take a look at this post:

link

    
26.07.2017 / 16:34
-1

The calculation of "Billed" can be rewritten to

-- código #1 v2
SELECT concat(CC.Descricao,'-', U1.UsuNome),
       C.CompDesc as QtdeCNPJs,    
       case when exists (SELECT * 
                           from Tarefa as T1
                           where T1.ProjID = PP.ProjID
                                 and T1.TarStatus = 9
                                 and T1.TarTitulo = 'Treinamento Realizado - Emitir Boleto Setup'
                                 and T1.TarTipID = 674
                                 and T1.TarEstagioID = 112)
            then 'SIM' 
            else 'NÃO' end as Faturado
  from PROJETOS as PP
... 

This is a correlated subquery .

In this subquery you do not need to use the Projects table; just establish the direct correlation with the External Query Projects table.

    
26.07.2017 / 22:59