code_legend
code_legend

Reputation: 3285

Execute query if information is found in a specific column

I have the following query:

SELECT box, name from box where 'name' !=  '' 

but it doesn't seem to take into account the where condition into account and execute the entire query as if that condition was not there.

I essentially want to only retrieve data where there is information found in the name column.

Any help would be appreciated

Upvotes: 0

Views: 40

Answers (3)

Anakhin
Anakhin

Reputation: 1

have you tried where notnull(name,'') <> '' ?

Upvotes: -1

Matt
Matt

Reputation: 14341

SELECT box, name from box where 'name' !=  '' 

'name' is a string so the string 'name' is NOT EQUAL to the string '' which is always true.

SELECT box, name from box where name != ''

If you want where a string is not null and not empty string then you could do something like this:

SELECT box, name from box where COALESCE(name,'') != ''

and to take into account whitespace

SELECT box, name from box where COALESCE(TRIM(name)),'') != ''

Upvotes: 2

Wild Beard
Wild Beard

Reputation: 2927

Try name <> NULL on your query or IS NOT NULL

Upvotes: 0

Related Questions