高手帮忙,查询写了一半,下面的不会了
有一表oitm,有一列的数据为:fcc090101a,fcc090102a,fcc090103a,fcc090106a,fcc090107a,fcc090110a.....
现在要把数据分离为 101,102,103,106,107,110.....
然后列出其中缺少的数字 104,105,108,109
请问这个查询要如何做呢?
我的想法是把 101,102,103,106,107,110等分离出来写到表 #tt里面,
然后生成另一个临时表#tst,数据为 101,102,103,104,105,106,107,108,109,110
然后比较,其中缺少的就是了,但是我写了一半,下面的不会写了,高手帮忙。。。。
if OBJECT_ID('tempdb..#tt') is not NULL
drop table #tt
select distinct convert(int,SUBSTRING(ItemCode,7,3)) as substr
into #tt
from OITM
where ItemCode between 'fcc090101a' and 'fcc091010a'
declare @start int
declare @end int
select @start = min(substr),@end = max(substr)
from #tt
if OBJECT_ID('tempdb..#tst') is not NULL
drop table #tst
现在要把数据分离为 101,102,103,106,107,110.....
然后列出其中缺少的数字 104,105,108,109
请问这个查询要如何做呢?
我的想法是把 101,102,103,106,107,110等分离出来写到表 #tt里面,
然后生成另一个临时表#tst,数据为 101,102,103,104,105,106,107,108,109,110
然后比较,其中缺少的就是了,但是我写了一半,下面的不会写了,高手帮忙。。。。
if OBJECT_ID('tempdb..#tt') is not NULL
drop table #tt
select distinct convert(int,SUBSTRING(ItemCode,7,3)) as substr
into #tt
from OITM
where ItemCode between 'fcc090101a' and 'fcc091010a'
declare @start int
declare @end int
select @start = min(substr),@end = max(substr)
from #tt
if OBJECT_ID('tempdb..#tst') is not NULL
drop table #tst
...全文


应用实例
