日期:2014-05-17 浏览次数:20423 次
drop table tb
Create table tb(ch char(1));
Insert into tb(ch) values('A'),('C');
Select *,identity(int,1,1)as rn
Into ot
From tb
order by ASCII(ch);
Select top(1) CHAR(ASCII(t1.ch) +1) as minchar
From ot as t1
Left Join ot as t2
On ASCII(t1.ch) = ASCII(t2.ch) -1
Where t2.rn is null
-----
B
create table ayu(name char(1))
insert into ayu
select 'A' union all
select 'C' union all
select 'E'
select min(a.name) 'name'
from
(select char(64+number) 'name'
from master.dbo.spt_values
where [type]='P' and number between 1 and 26) a
left join
(select distinct [name] from ayu) b on a.name=b.name
where b.name is null
/*
name
----
B
(1 row(s) affected)
*/