本文介绍了如何在sql server中插入正确的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有开发人员下午好,



以下是我的ODRange表结构,现在如果用户进入范围



最小值= 23最大值= 30 - 然后它有效,因为表中不存在该范围

最小值= 35最大值= 40 - 无效,因为范围b / n 31到37已经存在。应该避免重叠



那么如何检查用户是否输入了正确的范围,根据该比较,我们必须显示其是否有效..



Good Afternoon to all Developers,

The following is my "ODRange" table structure, Now if user enters the range

Minimum=23 Maximum=30 --Then its valid because that range doesn't exists in the table
Minimum=35 Maximum=40 --Invalid, Because the range b/n 31 to 37 already exists.Overlapping Should be avoided

So how to check whether the user enters the correct range or not, On basis of that comparision, We have to display whether its valid or not..

Minimum  Maximum
1	10
11	22
31	37
45	52
58	69
70	86
87	90
97	102
103	107





范围应插入特定位置。



预先感谢任何建议..!



The range should be inserted at the particular position.

Thanks in Advance for any suggestion..!

推荐答案


IF EXISTS (SELECT 1 FROM ODRange WHERE 31 <= maximum AND 37 >= Minimum)
  print 'Overlaps'
ELSE
  print 'Does not overlap'





- 阿米特


declare @min int
declare @max int

set @min= 35
set @max= 40


if exists(select * from ODRange where (minimum<=@min and maximum >=@min) or (minimum<=@max and maximum >=@max))
print 'Invalid Range'
else
insert into ODRange values(@min,@max)


这篇关于如何在sql server中插入正确的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:56