Condition called null data, from a subselect - transact sql

0

I need to see purchases that do not have a nombre_etapa associated with it.

I leave the code:

SELECT
re.[compras] AS compras,
(
SELECT e.[nombre] as nombre_etapa_e
FROM [Control_Documental].[dbo].[Registro_Etapa_Documento] AS e
) as nombre_etapa
FROM [Control_Documental].[dbo].[Requisicion] AS re 
LEFT JOIN [Control_Documental].[dbo].[Registro_Etapa_Documento] AS e ON e.[idEtapa] = re.[idEtapa]
WHERE 
e.[nombre] IS NULL

It looks very simple, but I do not know how to bring it. I currently call it as I wrote it above, but it does not bring me any data, being that there are purchases that do not have associated e.[nombre] .

This query is much more complex, I just summarized it, the subselect if necessary. The subject is how to call when it is an subselect that brings a data, from the WHERE main of the query.

If I wanted to call the empty associations of re.[compras] I just call them with WHERE re.[compras] IS NULL . but when there is a subselect that brings the data, I can not see how to bring the null data.

    
asked by Francisco Acevedo 28.09.2017 в 05:55
source

2 answers

0

You can use the COALESCE function

SELECT COALESCE(e.[nombre],"Este dato es nulo") as nombre_etapa_e
FROM [Control_Documental].[dbo].[Registro_Etapa_Documento] AS e
    
answered by 28.09.2017 в 06:04
0

I do not understand what is the reason why you do a subselect of the table, the only reason why it would be pertinent to do the subselect is if your table has many fields, but good from what I understand you want to make the comparison between two tables A and B and you want to bring the results that exist in A but do not exist in B Is it correct? If this is true you can do it in the following way

select *
from tablaA A
full outer join tablaB
on a.id = b.id
where b.id is null

This makes a join of your two tables if it exists in A and not in B puts you the record of A and B leaves it in null and void. but how are we filtering that b is null then it returns only what exists in A and in B does not exist.

I hope I could have helped you and if you have any questions you can send me a message, to help you, regards!

    
answered by 28.09.2017 в 06:29