Sigma
Sigma

Reputation: 15

IF type of statement in SELECT

wondering if there is a way do this kind of if in SELECT block.

SELECT
   [  if Table1.field == NULL 
      then
         Table2.field
      else
         Table3.field
   ] as OutputField

i checked the IFF and CASE-WHEN, doesn't seem to support this.

Upvotes: 0

Views: 35

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520859

On MS Access database, you would use IIF along with ISNULL:

SELECT
    IIF(ISNULL(Table1.Field), Table2.Field, Table3.Field) AS OutputField
FROM yourTable

Upvotes: 1

juergen d
juergen d

Reputation: 204746

You need to use IS for NULL checks:

select case when Table1.field IS NULL 
            then Table2.field
            else Table3.field
       end as OutputField
from ...

Upvotes: 1

Related Questions