Rewrite the title: SQL statement using WHERE clause of CASE statement
<p>
I was struggling with how to get p.oldversionref as output when writing the second statement when I need p.voided_date_key equal to 11082023. </p><p><br /></p>
<pre><code> select * from table1 as p
in
1 = (determined when p.accepted_date_key > '11082023'
Then 1
When p.voided_date_key = '11082023'
Then p.oldversionref then 1)
/code> </code></pre>
<code>
<p><br /></p></code>
Based on the information given, maybe this version may help:
SELECT *
FROM table1 AS p
WHERE
(CASE
WHEN p.accepted_date_key > '11082023' THEN 1
WHEN p.voided_date_key = '11082023' THEN p.oldversionref
ELSE 0
END) = 1;