我有这两张桌子
f_data
(
id (int, null),
name(varchar(255), null),
control (int, null),
)
ID名称控制
1255,ALMONTE JIMENEZ ADALGISA,1131238601
92,ENCARNACION PAMELA,1131237483
3376,Feliz Luis Manuel,1131240995
688,HerrandMariñeDioMedes,1131238666
1887,Jose Alberto Matos,1131240215
est_data
(
id(int, null),
name(varchar(255), null),
firstname(varchar(255), null),
lastname(varchar(255), null),
)
id name firstname lastname
201201255 ,ADALGISA ,ALMONTE ,JIMENEZ ,
201200092 ,PAMELA ,ENCARNACION ,,
201223376 ,LUIS MANUEL ,FELIZ ,,
201200688 ,DIOMEDES ,HERRAND ,MARIÑE,
20120188
和这个 SQL 代码
select *
from est_data
where
CASE
WHEN
lastname = ' '
then
ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(name))
ELSE
ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(lastname))+' '+ltrim(rtrim(name))
END in
(Select ltrim(rtrim(name)) From f_data where id = 1887)
结果:
CASE
WHEN
lastname = ' '
then
ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(name))
ELSE
ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(lastname))+' '+ltrim(rtrim(name))
END
是“何塞·阿尔伯托·马托斯”
结果:
Select ltrim(rtrim(name)) From f_data where id = 1887
是“何塞·阿尔伯托·马托斯”
但是代码返回0行,名称相同时的事件。这里可能有什么问题?
注意:我们使用的是 SQL Server 2000