--建立测试环境
Create table tb
(name Varchar(10),
flag Int,
tram Int
)Create table [temp]
(name Varchar(10),
flag Int
)
GO
--插入数据
Insert tb Values('A', 1, 12)
Insert tb Values('B', 2, 45)
Insert tb Values('C', 3, 56)
Insert tb Values('D', 4, 14)
Insert tb Values('E', 6, 4)Insert [temp] Values('A', 2)
Insert [temp] Values('B', 2)
Insert [temp] Values('C', 5)
Insert [temp] Values('D', 4)
Insert [temp] Values('E', 5)GO
--测试
Select * from tb Where name+Rtrim(flag) Not In (Select name+Rtrim(flag) from [temp])
--删除测试环境
Drop table tb,[temp]
--结果
/*
name flag tram
A 1 12
C 3 56
E 6 4*/
Create table tb
(name Varchar(10),
flag Int,
tram Int
)Create table [temp]
(name Varchar(10),
flag Int
)
GO
--插入数据
Insert tb Values('A', 1, 12)
Insert tb Values('B', 2, 45)
Insert tb Values('C', 3, 56)
Insert tb Values('D', 4, 14)
Insert tb Values('E', 6, 4)Insert [temp] Values('A', 2)
Insert [temp] Values('B', 2)
Insert [temp] Values('C', 5)
Insert [temp] Values('D', 4)
Insert [temp] Values('E', 5)GO
--测试
Select * from tb Where name+Rtrim(flag) Not In (Select name+Rtrim(flag) from [temp])
--删除测试环境
Drop table tb,[temp]
--结果
/*
name flag tram
A 1 12
C 3 56
E 6 4*/
(
name varchar(1),
flag int,
tram int
)create table [temp]
(
name varchar(1),
flag int
)insert into tb
select 'A', 1, 12
union all
select 'B', 2, 45
union all
select 'C', 3, 56
union all
select 'D', 4, 14
union all
select 'E', 6, 4insert into [temp]
select 'A', 2
union all
select 'B', 2
union all
select 'C', 5
union all
select 'D', 4
union all
select 'E', 5select a.name, a.flag, a.tram from [temp] b, tb a
where a.name = b.name and a.flag<>b.flagdrop table [temp]
drop table tb
A 1 12
C 3 56
E 6 4
以上两种方法均有漏洞!
-----------------------指出漏洞所在!!
是我看的不仔细,看他的name 都一样就把name忽略了!
from tb
where flag not in
(select a.flag from tb a,temp b where a.name=b.name and a.flag=b.flag)
gsh945(太平洋底) ( ) 信誉:100 2005-04-08 23:53:00 得分: 0
以上两种方法均有漏洞!
-----------------------指出漏洞所在!!tb 中有记录
A1 1 *
temp 中有记录
A 11你的算法在这种情况下不行!!
select * from tb where not exists(select * from temp where name=tb.name and flag=tb.flag)这个行!!
回复人: paoluo(一天到晚游泳的鱼) ( ) 信誉:100
gsh945(太平洋底) ( ) 信誉:100 2005-04-08 23:53:00 得分: 0
以上两种方法均有漏洞!
-----------------------指出漏洞所在!!tb 中有记录
A1 1 *
temp 中有记录
A 11你的算法在这种情况下不行!!
--------------------------------------------------------------------
你说的的确有道理,在某些情况的确会出错。但是你看看楼主的字段,分别是name、flag,一个是Nvarchar的,一个是Int,会出现你那种情况吗??