当前位置: 代码迷 >> Sql Server >> 怎么查询在一个表的两个字段之单的数据
  详细解决方案

怎么查询在一个表的两个字段之单的数据

热度:70   发布时间:2016-04-27 14:23:36.0
求助:如何查询在一个表的两个字段之单的数据


如图aa表中的两个字段
如何查询002在001和003之间
如何查询005在004和006之间
我要的结果是当我插入002的时候提示该数据已经存在了,只求sql语句。大侠们帮帮忙,谢谢!

------解决方案--------------------
SQL code
declare @i varchar(10)='002'if exists(select 1 from tb where beginno<@i and endno>@i)print [email protected] 已经存在
------解决方案--------------------
SQL code
declare @a varchar(3)set @a='002'if exists (select 1 from tb where @a >beginno and @a<endno)print '该数据已经存在了'elseinsert into tb ......
  相关解决方案