首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

再问where 后加条件有关问题

2012-12-22 
再问where 后加条件问题sql如下:select * from tes wheredjb case when @djb 102 then 101 else @djb

再问where 后加条件问题
sql如下:

select * from tes where  djb = case when @djb = 102 then 101 else @djb end and
                           ((@djb <> 102 and kctdj is null) or (@djb = 102 and not kctdj is null))


以上存储过程在sql里执行没有问题

但若@djb 为101时 在delphi用ADOStoredProc1打开时提示错误如下:

“数据提供程序或其他服务返回 E_FAIL 状态。”

检查后发现这个条件的问题:(@djb <> 102 and kctdj is null)

条件目的:如果@djb=102 就筛选kctdj列不为空的记录,否则就筛选kctdj列为空的记录。


请问如何修改呀?  
[最优解释]
“数据提供程序或其他服务返回 E_FAIL 状态。”

可能不是sql语句的问题吧,语法没问题,最多返回到 是空集,没有数据。建议再看看你的前台程序。
[其他解释]
not kctdj is null 改為 kctdj is not null


[其他解释]
select * from tes where  djb = case when @djb = 102 then 101 else @djb end and                           ((@djb <> 102 and kctdj is null) or (@djb = 102 and not kctdj is null)) 


抛开kctdj这个字段,你@djb <> 102或者@djb =102这个是不是有点.......

热点排行
Bad Request.