I am trying to put the Case statement in Where clause but DB gives me error:-
3706. Syntax Error : expected something between ')' and the 'between' keyword.
Is Teradata supports the Where clause with Case statement.
Select Start_time_id, datetime from Datetime_Table Where Case When 'Previous Day' then ((Start_time_id) between 12345 And 123459) When 'Previous Week' then ((Start_time_id) between 23456 And 234459) END
Re: Where Clause with CASE WHEN THEN END statement.
In a CASE expresssion, THEN must be followed by a scalar value expression. The entire CASE expression evaluates to a scalar value, not a predicate. You can use CASE in a WHERE clause, but the outer expression must be used in a predicate, as in the following example:
SELECT * FROM t WHERE x = CASE WHEN y=2 THEN 1 ELSE 2 END;