I have this query (pseudo code)
SELECT
a = 1,
b = 2,
c = CASE
WHEN ISNULL(
(SELECT MONTH(GETDATE()) <---long query
), 0) = 0 THEN 'found'
ELSE
SELECT MONTH(GETDATE()) <--- repeated long query
END
The problem is that the SELECT MONTH(GETDATE()) which in reality is very long query.
Is there any workaround for this "long expression" not to appear twice in the query ?
p.s.
I have a solution of calculating SELECT MONTH(GETDATE()) into an outside variable... but I'm trying to figure out if there's an inline solution.
cross applyif your query always return one row andouter applyif it returns zero or one row.