Ozk*_*kan 0 sql sql-server sql-server-2005
我有一个Microsoft SQL表,tbl
其中包含以下记录:
clmn1 (smallint NOT NULL) = '2012'
clmn2 (char (10) NOT NULL) = '620100'
clmn3 (char (1) NOT NULL) = ''
Run Code Online (Sandbox Code Playgroud)
当我执行以下查询时:
select *
from tbl with (rowlock)
where clmn1 = 2012 and clmn2 = '620100' and clmn3 <= ' '
Run Code Online (Sandbox Code Playgroud)
然后找到上面的行,这是正确的.
但是在执行以下查询时:
select *
from tbl with (rowlock)
where clmn1 = 2012 and clmn2 = '620100' and clmn3 < ' '
Run Code Online (Sandbox Code Playgroud)
然后它找不到任何不正常的东西.因为clmn3是空的('').'' < ' ' = true
.
必须使用这种2 sql查询格式,因为我们正在使用Xisam将自己的sql查询转换为上述sql查询格式.
CHAR(1)
转''
成' '
...所以' '
是不是 < ' '
.如果要将空字符串视为空字符串,请停止使用CHAR
并使用VARCHAR
.
DECLARE @c CHAR(1);
SET @c = '';
SELECT 'x' + @c + 'x';
Run Code Online (Sandbox Code Playgroud)
结果:
x x -- not xx
Run Code Online (Sandbox Code Playgroud)