0
votes

This should be simple, but the solution keeps eluding me. Teradata 16.20.32.10.
Currently in a Teradata Macro. Macro will eventually be used in an SSRS report, where they can only choose Y or N.

Macro has a parameter: Paramater1

Date is in TableX:
    Datefield
    ID
    Q1 (Y/N)
    Q2 (Y/N)

If Parameter1 = Y
    Then Q1 must = Y
         Q2 must = Y

If Parameter1 = N
    Then everything

My attempt (which errors):

SELECT TOP 10
 DateField
,ID 
,Q1
,Q2
FROM TABLEX
WHERE DateField = DATE  /*Today*/
AND CASE 
     WHEN Parameter1 = 'Y'
       THEN Q1 = 'Y'
           ,Q2 = 'Y'
ELSE Q1 IN ('Y','N')
     Q1 IN ('Y','N')
1

1 Answers

2
votes

You don't need a case expression. Simple boolean logic suffices:

where (parameter1 = 'Y' and q1 = 'Y' and q2 = 'Y') or
      (parameter1 = 'N' and q1 in ('Y', 'N') and q2 in ('Y', 'N'))