Dani-Br
Dani-Br

Reputation: 2457

display one of two fields in every row

I have table like:

+------+-----+
| name | nick|
+------+-----+
| yosi | Y   |
| adam | NULL|
+------+-----+

I need output of one column, of nick if nick is not null, or of name if nick is null.
like this:

+------+
|result|
+------+
| Y    |
| adam |
+------+

Is there a query for that ?

Upvotes: 0

Views: 90

Answers (3)

maxhugen
maxhugen

Reputation: 1944

In Access, I use the nz() function for that, eg:

SELECT nz(nick, name) as result FROM table

Upvotes: 1

dee-see
dee-see

Reputation: 24088

SELECT IFNULL(nick, name) as result FROM table

This will work in MySQL. See documentation here.

Upvotes: 4

Andrey
Andrey

Reputation: 1818

SELECT ISNULL(nick, name) as result FROM table 

for Access and SQL server

Upvotes: 1

Related Questions