Where Clause with CASE WHEN THEN END statement.

Database
N/A

Where Clause with CASE WHEN THEN END statement.

Hi,

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.

Query like:-

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

Please suggest me..

Or explain me with some example.

Regards,
Akash
2 REPLIES
Enthusiast

Re: Where Clause with CASE WHEN THEN END statement.

Hi,

Against which column you want to quantify or what is the exact requirement?
Enthusiast

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;