declare @str int set @str=0 select 6/isnull(@str,1)
declare @str int set @str=0 select 6/isnull(@str,1)
select *, g = case when A.f = 0 then 0 else A.e/A.f end from A
update A set g=(case when f=0 then 0 when f<>0 then e/f end)
select case a.f when 0 then 0 else a.e/a.f end from tb
select isull(12/nullif(0,0),0) 这个函数好用
DECLARE @table TABLE(f1 numeric(18,2),f2 int,f3 numeric(18,2))--测试数据 insert into @table (f1,f2,f3) select 12,5,null union all select 10,0,null union all select 89,null,null union all select 56,3,null--除法前 select * from @table--做除法 update @table set f3= case when isnull(f2,0)=0 then null else f1/f2 end--除法后 select * from @table
declare @str int
set @str=0
select 6/isnull(@str,1)
declare @str int
set @str=0
select 6/isnull(@str,1)
select *,
g = case when A.f = 0 then 0 else A.e/A.f end
from A
select case a.f when 0 then 0 else a.e/a.f end from tb
这个函数好用
insert into @table (f1,f2,f3)
select 12,5,null union all
select 10,0,null union all
select 89,null,null union all
select 56,3,null--除法前
select *
from @table--做除法
update @table
set f3= case when isnull(f2,0)=0 then null else f1/f2 end--除法后
select *
from @table
(所影响的行数为 4 行)f1 f2 f3
-------------------- ----------- --------------------
12.00 5 NULL
10.00 0 NULL
89.00 NULL NULL
56.00 3 NULL(所影响的行数为 4 行)
(所影响的行数为 4 行)f1 f2 f3
-------------------- ----------- --------------------
12.00 5 2.40
10.00 0 NULL
89.00 NULL NULL
56.00 3 18.67(所影响的行数为 4 行)