Pearl
Pearl

Reputation: 534

How to check whether a string is null or not?

Could any one give me an idea to check whether a string is null or not without making use of followin:

1. length(string)
2. Comparing string with ""
3. string ! = NULL

Upvotes: 2

Views: 2596

Answers (4)

onedaywhen
onedaywhen

Reputation: 57073

CASE WHEN NULLIF(some_text, '') IS NULL THEN 'T' ELSE 'F' END

Upvotes: 0

Mr Moose
Mr Moose

Reputation: 6354

I'm not sure exactly what your asking, but you can check for null using IS NULL;

SELECT 1 WHERE '' IS NULL

or

SELECT 1 WHERE NULL IS NULL

Upvotes: 0

Wim ten Brink
Wim ten Brink

Reputation: 26682

Use string IS NOT NULL. Using string != NULL is not valid SQL...

Upvotes: 3

Talha Ahmed Khan
Talha Ahmed Khan

Reputation: 15473

use IS NOT NULL on String

Like

SELECT * FROM table WHERE someString IS NOT NULL

Upvotes: 7

Related Questions