Here’s my queries, they don’t work but I want to do something like this :
SELECT a_field FROM a_table
WHERE
...
AND
CASE
WHEN a_value_from_another_query IS NULL THEN a_second_field IS NULL
ELSE a_second_field = a_value_from_another_query
END
Or
SELECT a_field FROM a_table
WHERE
...
AND
CASE a_value_from_another_query
WHEN NULL THEN a_second_field IS NULL
ELSE a_second_field = a_value_from_another_query
END
Or
SELECT a_field FROM a_table
WHERE
...
AND
CASE NVL(a_value_from_another_query, 'x')
WHEN 'x' THEN a_second_field IS NULL
ELSE a_second_field = a_value_from_another_query
END
When a_value_from_another_query IS NULL, I want to add a_second_field IS NULL to my WHERE clause, when a_value_from_another_query IS NOT NULL, I want to add a_second_field = a_value_from_another_query to my WHERE clause. How can I achieve this ?
Sounds like you simply picked up the wrong tool from the toolbox.
Unless I have horribly misunderstood you, the following:
… should so what you want.