--> 测试数据:# if object_id('tempdb.dbo.#') is not null drop table # create table #(起始编号 varchar(8), 终止编号 varchar(8)) insert into # select '005', '010' union all select '020', '030'if not exists (select 1 from # where 起始编号<='008' and 终止编号>='025') select '提示发票不存在'
有连续一样的思维 --> 测试数据:# if object_id('tempdb.dbo.#') is not null drop table # create table #(起始编号 varchar(8), 终止编号 varchar(8)) insert into # select '005', '006' union all select '007', '010' union all select '020', '030'if not exists (select 1 from # a left join # b on a.起始编号 = b.终止编号 + 1 where isnull(b.起始编号,a.起始编号)<='008' and isnull(a.终止编号, b.终止编号) >= '010') select '提示发票不存在'else select '提示发票存在'
if object_id('tempdb.dbo.#') is not null drop table #
create table #(起始编号 varchar(8), 终止编号 varchar(8))
insert into #
select '005', '010' union all
select '020', '030'if not exists (select 1 from # where 起始编号<='008' and 终止编号>='025')
select '提示发票不存在'
--> 测试数据:#
if object_id('tempdb.dbo.#') is not null drop table #
create table #(起始编号 varchar(8), 终止编号 varchar(8))
insert into #
select '005', '006' union all
select '007', '010' union all
select '020', '030'if not exists (select 1 from # a left join # b on a.起始编号 = b.终止编号 + 1
where isnull(b.起始编号,a.起始编号)<='008' and isnull(a.终止编号, b.终止编号) >= '010')
select '提示发票不存在'else
select '提示发票存在'