如果楼主同意我的条件,那么用以下语句就可以帮你搞定问题了
//id2是临时创建的自增列
--在查之前创建ID2为自增列(楼主自已写)
select id2 from aa where id2 not in
(
select isnull(b.id2,0) id2 from
(select * from aa ) a
left join
aa b
on a.id=b.id2
)
--查完后删除临时列ID2(楼主自已写)
很土!!!!!!!!!!
搞定,给分,呵呵
//id2是临时创建的自增列
--在查之前创建ID2为自增列(楼主自已写)
select id2 from aa where id2 not in
(
select isnull(b.id2,0) id2 from
(select * from aa ) a
left join
aa b
on a.id=b.id2
)
--查完后删除临时列ID2(楼主自已写)
很土!!!!!!!!!!
搞定,给分,呵呵
as
select number from
(
select t1.b+t2.b*10+t3.b*100+t4.b*1000 number
from
(
select 0 b union all select 1 b union all select 2 b union all
select 3 b union all select 4 b union all select 5 b union all
select 6 b union all select 7 b union all select 8 b union all select 9 b
) t1,
(
select 0 b union all select 1 b union all select 2 b union all
select 3 b union all select 4 b union all select 5 b union all
select 6 b union all select 7 b union all select 8 b union all select 9 b
) t2,
(
select 0 b union all select 1 b union all select 2 b union all
select 3 b union all select 4 b union all select 5 b union all
select 6 b union all select 7 b union all select 8 b union all select 9 b
) t3,
(
select 0 b union all select 1 b union all select 2 b union all
select 3 b union all select 4 b union all select 5 b union all
select 6 b union all select 7 b union all select 8 b union all select 9 b
) t4
) t5
where number<>0
--用左外连接找到clothid中的cid不在v_number中的数
select number
from v_number left outer join clothid on number = cid
where cid is null and number <(select max(cid) from clothid)
order by number
Id =8呢﹖建議再換一種思路
是说我的方法吗,
我的方法不可能不行的!!!!!!
不知你试过没有
(select top 100 from master..sysobjects
union
select top 100 from master..sysobjects
union
select top 100 from master..sysobjects
...
)
select id form #temp where id not in (select id from YourTable)
你的方法有这样的问题
1)首先不能在原表上继续创建标识列 因为每个表只能有一个标识列 必须导入到临时表才行
select identity(int,1,1) as newid ,原表中不是id的字段 into #tmp from tb
2)再按照你的方法 取出的id号只能去一部分 不是完整的
比如已经删除了5个数据 只能取出4个id 而最后一个id丢失了
可以这样看一下
clothid #tmp
id newid
1 1
2 2
4 3
6 4
7 5
10 6
12 7
13 8
14 9
比较结果 id 为11的删除数据 无法找到
我的前提是你在删数据时,同时把临时列删了,再建回去,
你所说的问题和我的问题会发生的原因都是因为#TMP最大值小于CLOTHID的其中的一个值,
为再为它加上一些条件看看
》1)首先不能在原表上继续创建标识列 因为每个表只能有一个标识列
为什么不行,它不是主键,如果从可行性方面考虑,是可以的,因为我已试过,
其它的原因就看楼主最后决定了再看看我的方法。。
共同研究!!
declare @temptable table(a int)
insert @a values(1,'a')
insert @a values(5,'b')declare @char varchar(1000),@i int,@num int
set @num=(select max(a) from @a)
set @i=1
while @i<=@num
begin
insert @temptable values (@i)
set @i=@i+1
end
select a from @temptable where a not in (select a from @a)