在SQL语句里用什么函数可以判断一个字段的值是否为0 ?

wealth 2004-09-27 12:00:09

在SQL语句里用什么函数可以判断一个字段的值是否为0 ?
...全文
1022 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wealth 2004-09-28
  • 打赏
  • 举报
回复

thanks !
lxysjl 2004-09-27
  • 打赏
  • 举报
回复
select field1/(case field2 when 0 then 1 else field2 end) from test
lsxaa 2004-09-27
  • 打赏
  • 举报
回复
select case field2 when 0 then 0 else field1/field2 end from test
wealth 2004-09-27
  • 打赏
  • 举报
回复

是这样的,现在要:

select field1 / field2 from test

这个 field2 为0就不行啦,各位是怎么处理的?
victorycyz 2004-09-27
  • 打赏
  • 举报
回复
直接判断就行啊。

select * from tablename where fieldname=0
bernice99 2004-09-27
  • 打赏
  • 举报
回复
isnull(字段,0)
检测字段是否为null,如果字段为null就用0代替
pbsql 2004-09-27
  • 打赏
  • 举报
回复
where 字段=0不是吗
zhangzs8896 2004-09-27
  • 打赏
  • 举报
回复
declare @file1 dec(3,2),@file2 dec(5,2)
set @file1=5
set @file2=0

select 结果=@file1/(case @file2 when 0 then 1 else @file2 end)

--结果:

结果
-------------
5.00000000

怎么会不可以呢,楼上真搞笑
azh9703 2004-09-27
  • 打赏
  • 举报
回复
case when我以前试过,但是在SQL-PLUS中通不过。请注意语法规则要符合SQL。
azh9703 2004-09-27
  • 打赏
  • 举报
回复
流星雨按照字面理解是对的。但是语句执行通不过。
zhangzs8896 2004-09-27
  • 打赏
  • 举报
回复
楼上的,流星雨的也该是对的。

这就看楼主的意思了。
判断的话是用case when结构
不知道楼主在file2为0时,想要的是什么结果了
azh9703 2004-09-27
  • 打赏
  • 举报
回复
select field1/decode(NVL(field2,0),0,1,field2) from test ;
说明NVL和DECODE都是SQL的函数,具体功能可以网上搜索
楼上case field2 when 0 then 1 else field2 end只能用在数据窗口作为表达式用,在语句中是不可以这样用的

34,590

社区成员

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

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