1、游标占用资源比较大2、Declare @temp_pjxfjd float SELECT @temp_pjxfjd = case when JX_Score.Credit=1 then 0 when JX_Score.Credit=2 then 1 when (JX_Score.Credit<>1 and JX_Score.Credit<>2) then 3 end from JX_score where .....如果根据条件一条记录都没有。那@temp_pjxfjd=3
--测试第二个问题--测试数据 create table 表(aa float) insert 表 select 1 union all select 2 union all select 3 go--查询 Declare @temp_pjxfjd float SELECT @temp_pjxfjd = case when aa=1 then 0 when aa=2 then 1 when (aa<>1 and aa<>2) then 3 end from 表 where aa>100select @temp_pjxfjd go--删除测试环境 drop table 表/*--测试结果(所影响的行数为 3 行) ----------------------------------------------------- NULL(所影响的行数为 1 行)--*/
SELECT @temp_pjxfjd = case when JX_Score.Credit=1 then 0 when JX_Score.Credit=2 then 1 when (JX_Score.Credit<>1 and JX_Score.Credit<>2) then 3 end
from JX_score where .....如果根据条件一条记录都没有。那@temp_pjxfjd=3
create table 表(aa float)
insert 表 select 1
union all select 2
union all select 3
go--查询
Declare @temp_pjxfjd float
SELECT @temp_pjxfjd = case when aa=1 then 0 when aa=2 then 1 when (aa<>1 and aa<>2) then 3 end
from 表 where aa>100select @temp_pjxfjd
go--删除测试环境
drop table 表/*--测试结果(所影响的行数为 3 行)
-----------------------------------------------------
NULL(所影响的行数为 1 行)--*/
但结果好像不是这样的,我判断了
if @temp_pjxfjd=null
print '1'
else
print '2'
结果是2
请指教
呵呵,问题不是这样的。。
print '1'
else
print '2'
如果省略else参数并且比较运算取值不为 TRUE,CASE 将返回 NULL 值。
set ansi_nulls off
if @temp_pjxfjd = null
print '1'
else
print '2'
set ansi_nulls on
print '1'
else
print '2'