Macbernie Macbernie - 1 year ago 72
SQL Question

Return 0 1 instead of data values

I have a simple SELECT request

SELECT firstname, lastname, age, country
FROM mytable

returning somethink like

jean dupont 35 france
hervé yang japon
laura 28
mickael sylvain 65 suisse

I want returning 1 (or true) when the field is not null, and 0 (or false) when the field is null.

In my exemple, the request should return

1 1 1 1
1 1 0 1
1 0 1 0
1 1 1 1

Thanks for help

hvd hvd
Answer Source

You can select boolean expressions directly to get true or false as your result.

  firstname IS NOT NULL,
  lastname IS NOT NULL,
  age IS NOT NULL,
  country IS NOT NULL
FROM mytable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download