Select a column if other column is null

后端 未结 7 753
庸人自扰
庸人自扰 2020-12-08 13:14

I need to select a field called ProgramID from a table and if the ProgramID is NULL then I need to select the value in the InterimProgramID from the same table and alias it

7条回答
  •  星月不相逢
    2020-12-08 13:38

    You need the ISNULL function.

    SELECT ISNULL(a, b)
    

    b gets selected if a is null.

    Also, you can use the WHEN/THEN select option, lookup in BOL. Essentially: its c switch/case block meets SQL.

提交回复
热议问题