Home  >  Q&A  >  body text

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>
P粉969253139P粉969253139459 days ago444

reply all(1)I'll reply

  • P粉561438407

    P粉5614384072023-08-11 12:52:37

    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;

    reply
    0
  • Cancelreply