Active
Active

Reputation: 143

Check for NULL or empty variable (MySQL stored procedure)

Can someone indicate the proper syntax to determine whether a variable is NULL or empty and then take appropriate action to set the variable depending on the result.

I currently have a test for NULL which works fine (part of a MySQL SELECT statement / stored procedure).

IFNULL(@previousTs, '2017-00-04 00:00:01') ts

I want to include (in the same single line) a test for empty (NULL or empty both results in @previousTs being set to 2017-00-04 00:00:01).

Upvotes: 4

Views: 6241

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172408

You can try like this:

IF(@previousTs IS NULL or @previousTs= '', '2017-00-04 00:00:01', @previousTs )

Upvotes: 4

Related Questions