请教关于CASE WHEN 的一个写法

静远 2010-03-12 04:21:00
假设有四个字段A,B,C,D
当A或B为空值时,C取D的值,否则C取自己本身的值

请问用case when可以实现吗?
...全文
130 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ICrazyBoy 2010-03-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 fredrickhu 的回复:]
SQL code
select a,b,case when a is null or b is null then d else c end as c from tb
[/Quote]

F姐姐 数据专家已经帮你game over了!
GUOCHENGJUN 2010-03-12
  • 打赏
  • 举报
回复

select c=case
when a is null then d
when b is null then d
else c end from 表名
静远 2010-03-12
  • 打赏
  • 举报
回复
大家的速度好快!
Mr_Nice 2010-03-12
  • 打赏
  • 举报
回复
select case when a is null or b is null then d else c end from tb
--小F-- 2010-03-12
  • 打赏
  • 举报
回复
select a,b,case when a is null or b is null then d else c end as c from tb
SQL77 2010-03-12
  • 打赏
  • 举报
回复
select a,
b,
c=case when ISNULL(A,'')='' or ISNULL(B,'')='' then d else c end
from tb
sql_sf 2010-03-12
  • 打赏
  • 举报
回复
select a,
b,
c=case when a is null or b is null then d else c end
from tb
黄_瓜 2010-03-12
  • 打赏
  • 举报
回复
select c=case when a is unll or b isnull then d else c end
sgtzzc 2010-03-12
  • 打赏
  • 举报
回复
select a,b,c=case when a is null or b is null then d else c end,d
from tb
csuxp2008 2010-03-12
  • 打赏
  • 举报
回复
update table_name
set c=case when (a is null or b is null) then d
else c
end
dawugui 2010-03-12
  • 打赏
  • 举报
回复
select case when a is null or b is null then d else c end from tb

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧