Doubt in SELECT CASE WHEN EXISTS statement

Database

Doubt in SELECT CASE WHEN EXISTS statement

Can we use such query in teradata

Hi i'm trying to execute the below query in teradata sql assistant.

SELECT TBL2.Column, (CASE WHEN EXISTS(SELECT Col1 FROM TBL1)

THEN '1' ELSE '0' END) AS TEMPCOL

FROM TBL2

But i'm getting illegal expression in when clause of case expression.

Pls help

2 REPLIES
Enthusiast

Re: Doubt in SELECT CASE WHEN EXISTS statement

Hi, exists() is filter condition. Case will not filter any records. Any filter can be provided in where, join, having, qualify.
Enthusiast

Re: Doubt in SELECT CASE WHEN EXISTS statement

Hi ,

Can you be specific about your requirement?

Don think we can use subqueries inside CASE statement. Instead you can join TBL1 and TBL2 and use IN in CASE statement like

SELECT TBL2.Column , CASE WHEN TBL2.column IN (TBL1.Col1) THEN '1' ELSE '0' END  AS TEMPCOL

FROM TBL2

JOIN TBL1

ON filter condition