一个郁闷的问题, 0=''
某普通查询,参数为INT,我传0进去
判断为''..
AND (@Edit_State IS NULL OR @Edit_State ='' OR Edit_State=@Edit_State)
print @Edit_State
if(@Edit_State='')
print 'kong'
print @Edit_State
输出:
0
kong
0
何解?
[解决办法]
不建议拿int型变量跟字符型做比较,
可以写为 @Edit_State=0 或 @Edit_State<>0
[解决办法]
declare @Edit_State int
set @Edit_State=0
print @Edit_State
if(@Edit_State='')
print 'kong'
print @Edit_State
/*
0
kong
0
*/
declare @Edit_State varchar(10)
set @Edit_State=0
print @Edit_State
if(@Edit_State='')
print 'kong'
print @Edit_State
declare @Edit_State varchar(10)
set @Edit_State=0
print @Edit_State
if(@Edit_State='')
print 'kong'
print @Edit_State
/*
0
0
*/
说明传送0参数时,与字符串比较,默认是空字符串
[解决办法]