如果其他列为空,则选择一列 [英] Select a column if other column is null

查看:20
本文介绍了如果其他列为空,则选择一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从表中选择一个名为 ProgramID 的字段,如果 ProgramID 为 NULL,那么我需要从同一个表中选择 InterimProgramID 中的值并将其别名为 ProgramID.

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 as ProgramID.

如何使用条件 SELECT 语句来执行此操作?

How can I make a conditional SELECT statement to do this?

推荐答案

您需要 ISNULL 函数.

You need the ISNULL function.

SELECT ISNULL(a, b)

ba 为空时被选中.

b gets selected if a is null.

此外,您可以使用 WHEN/THEN 选择选项,在 BOL 中查找.本质上:它的 c switch/case 块符合 SQL.

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

这篇关于如果其他列为空,则选择一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆