In a SQL query I was trying to work out a way to select a value from another B column if the selected A column is null . At first I made the following query:
SELECT COALESCE(NULLIF(max(convert(smalldatetime,DEP.DATAENTRADA,100)),null), DEP.DATANASCIMENTO,100) as UltimoDependente
from DEPENDENTES DEP
join FUNCIONARIOS FUNC on FUNC.FILIAL=DEP.FILIAL and FUNC.MATRICULA=DEP.MATRICULA and FUNC.D_E_L_E_T_ = ' '
where FUNC.MATRICULA = '10'
and FUNC.FILIAL = '01'
and DEP.R_E_C_D_E_L_=0
And the query does not work. Is there any way to accomplish this?