case when语句

abcwps 2009-10-27 11:01:57
表中有三个数字字段如下
table A
id,uname,num1,num2
1, 啊 10 0
2, 啊2 0 20
3, 啊1 15 20

select case num1 when isnull(num1,0) then num2 else num1 end as num3
from A

希望结果为
num3
10
20
15
但是结果为
0
20
0
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
abcwps 2009-10-27
  • 打赏
  • 举报
回复
谢谢。。
abcwps 2009-10-27
  • 打赏
  • 举报
回复
解决了。。
华夏小卒 2009-10-27
  • 打赏
  • 举报
回复

select case when num1=0 then num2 else num1 end as num3
from A
华夏小卒 2009-10-27
  • 打赏
  • 举报
回复

select case num1 when num1=0 then num2 else num1 end as num3
from A
nianran520 2009-10-27
  • 打赏
  • 举报
回复

select case isnull(num1,0) when 0 then num2 else num1 end as num3
from A

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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