Handling Null Value in Select statement

Database
Enthusiast

Handling Null Value in Select statement

Hi,

As my background is from ORACLE. That's why usually my questions are comparison of SQL I write in Oracle to the 1 I can write in teradata.

I want to handle NULL value in SELECT statement. What can I do?

Basically previously I asked

(Query Returns 1 if it is 2nd saturday of the month)

SELECT 1 FROM Sys_Calendar.Calendar C
WHERE C.calendar_date = current_date
AND C.day_of_week = 7
AND C.day_of_month between 8 and 14

Now I want this SELECT to return O(ZERO) if its NULL.

In ORACLE I would have done it like this

SELECT NVL(1,0) FROM Sys_Calendar.Calendar C
WHERE C.calendar_date = current_date
AND C.day_of_week = 7
AND C.day_of_month between 8 and 14

Thanks.
2 REPLIES
Enthusiast

Re: Handling Null Value in Select statement

Well I tired 'ZEROIFNULL' but it is not returing any thing.

Can someone shed some light on it. Or any other function I can use to get ZERO when its not 2nd Saturday of the month.

SELECT ZEROIFNULL(1)
FROM Sys_Calendar.Calendar C
WHERE C.calendar_date = CAST('10/02/2007' AS DATE FORMAT'DD/MM/YYYY')
AND C.day_of_week = 7
AND C.day_of_month between 8 and 14;

Thanks.

Enthusiast

Re: Handling Null Value in Select statement

I don't know exactly what you're trying to do, but will this work?

SELECT CASE WHEN C.day_of_week = 7 AND C.day_of_month between 8 AND 14
THEN 1
ELSE 0
END
FROM Sys_Calendar.Calendar C
WHERE C.calendar_date = current_date

This will always return one row that will contain a 1 if it is the second Saturday of the month and a 0 if it's not.