I try to make a query in a FUNCTION but this time with a condition that if in my table the "Strnttr" field is null grab the value of another column I show them my FUNCTION
is from the OJDT table where I want to apply it
ALTER FUNCTION [dbo].[SBO_FN_LGS_OBT_OBTENER_Fecha_doc](@Code varchar(50))
RETURNS varchar(250)
AS
BEGIN
DECLARE @resp datetime;
declare @st int;
select @st=StornoToTr from OJDT
SELECT @resp =b.TaxDate
from OJDT A INNER JOIN
(
select transid,U_LGS_TIPO,TaxDate,U_LGS_TIPO as tipo from oinv union all
select transid,U_LGS_TIPO,TaxDate,U_LGS_TIPO from opch union all
select transid,U_LGS_TPCE,TaxDate,U_LGS_TPCE from ovpm union all
select transid,U_LGS_TPCE,TaxDate,U_LGS_TPCE from ORCT union all
select transid,U_LGS_TIPO,TaxDate,U_LGS_TIPO from ODLN union all
select transid,U_LGS_TIPO,TaxDate,U_LGS_TIPO from orin union all
select transid,U_LGS_TPCE,TaxDate,U_LGS_TPCE from orct union all
select transid,U_LGS_TIPO,TaxDate,U_LGS_TIPO from owtr
) b
ON A.TRANSID=B.TRANSID and a.U_LGS_TIPO=b.tipo
where a.transid= @code
RETURN format(@resp,'dd/MM/yyyy');
END;