In SQL, how to assign the value of a column to null without using the CASE statement, using the nested NULLIF function when condition A or condition B is met
P粉310754094
P粉310754094 2023-08-25 13:26:01
0
2
456

I have a column C1 whose value can be 'values', 'empty' or 'N/A'.

| C1 | ------- | | | N/A | |apple|

I want to select column C1 in a way that converts null values and N/A to NULL, using NULLIF.

| C1 | ------- |NULL | |NULL | |apple|

We can use NULLIF(C1, ''), which returns NULL if the column value is empty.

We can also use CASE to achieve these two situations, but I want to know if there is a way to use NULLIF to achieve it, and if so, how to achieve it? (Or other methods besides CASE)

Similar to NULLIF(C1, '' OR 'N/A')

Thanks in advance.

P粉310754094
P粉310754094

reply all (2)
P粉253800312

UsecaseExpression:

(case when c1 not in ('', 'N/A') then c1 end)
    P粉925239921

    You can use nestedNULLIF()functions to achieve:

    NULLIF(NULLIF(c1, ''), 'N/A')

    SeeDemo.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!