Difference between revisions of "NULLIF"
From SQLZOO
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>NULLIF(f1,f2)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'...") |
|||
| Line 9: | Line 9: | ||
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr> | <tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr> | ||
</table> | </table> | ||
| + | |||
<h1>NULLIF</h1> | <h1>NULLIF</h1> | ||
<p>NULLIF returns NULL if the two arguments are equal; otherwise NULLIF returns the first argument. </p> | <p>NULLIF returns NULL if the two arguments are equal; otherwise NULLIF returns the first argument. </p> | ||
| Line 35: | Line 36: | ||
<li>[[COALESCE |COALESCE function]]</li> | <li>[[COALESCE |COALESCE function]]</li> | ||
</ul> | </ul> | ||
| + | |||
| + | {{Languages}} | ||
Latest revision as of 11:28, 28 October 2012
| NULLIF(f1,f2) | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | Yes | |
| mysql | Yes | |
| oracle | Yes | |
| postgres | Yes | |
| sqlserver | Yes | |
NULLIF
NULLIF returns NULL if the two arguments are equal; otherwise NULLIF returns the first argument.
NULLIF(x,y) = NULL if x=y NULLIF(x,y) = x if x != y
NULLIF can be used to replace a specific value with NULL. In this example the party Lab is replaced with NULL.
SELECT name, party ,NULLIF(party,'Lab') AS aff FROM gisq.msp WHERE name LIKE 'C%'
SELECT name, party ,NULLIF(party,'Lab') AS aff FROM msp WHERE name LIKE 'C%'
See also
| Language: | English • Deutsch |
|---|