Simple CASE Statement

Database
Highlighted

Simple CASE Statement

Hi all,

I have a case SQL statement. When I execute, it gives 3771 error. what is my mistake?

I try to write 'Y' when the CUST_ID is not null.

Thanks.

 

SELECT LLL.CUSTOMER_ID,

CASE LLL.EMAIL_SEND_FLAG

WHEN LLL.CUST_ID IS NOT NULL THEN 'Y'

END

FROM

(SELECT * FROM

.......) LLL

 

When I only execute SELECT * FROM ...... 

the results is like below.

 

CUSTOMER_ID     EMAIL_SEND_FLAG   CUST_ID

ID1     N     ID1

ID2     N       ?

ID3     N      ID3

 


Accepted Solutions
Teradata Employee

Re: Simple CASE Statement

You can say
CASE WHEN LLL.CUST_ID IS NOT NULL THEN 'Y' ...
or perhaps
CASE LLL.EMAIL_SEND_FLAG WHEN NOT NULL THEN 'Y' ...
or
CASE LLL.CUST_ID WHEN NOT NULL THEN 'Y' ...

But you really should add "ELSE NULL."  Even though that's the default, it helps clarify things to those who don't know it's the default.

1 ACCEPTED SOLUTION
2 REPLIES
Teradata Employee

Re: Simple CASE Statement

You can say
CASE WHEN LLL.CUST_ID IS NOT NULL THEN 'Y' ...
or perhaps
CASE LLL.EMAIL_SEND_FLAG WHEN NOT NULL THEN 'Y' ...
or
CASE LLL.CUST_ID WHEN NOT NULL THEN 'Y' ...

But you really should add "ELSE NULL."  Even though that's the default, it helps clarify things to those who don't know it's the default.

Re: Simple CASE Statement

Thank you very much.

Best regards GJColeman.

This SQL worked.

 

SELECT LLL.CUSTOMER_ID,

CASE

WHEN LLL.CUST_ID IS NOT NULL THEN 'Y'

ELSE 'N'

END AS EMAIL_SEND_FLAG

FROM

(SELECT *......) LLL