I have to make a query similar to
SELECT
CASE WHEN
(SELECT MAX(Fecha) FROM Tabla) > '01/01/1900' THEN (SELECT MAX(Fecha) FROM Tabla)
ELSE '01/01/1900' END
The problem is that the (SELECT MAX(Fecha) FROM Tabla)
is running twice. One to evaluate the data and another to show it.
The query (this is just an example) I have inside a function that returns a table and I can not declare variables in them.
Is there any way to avoid this without having to use a scalar function?