如何在sql server中插入正确的范围? [英] How to insert the correct range in sql server?

查看:84
本文介绍了如何在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..!

推荐答案

在sqlcommand中使用2个参数用户输入的最小和最大对象

创建datareader来运行查询select * from tab,其中min = @ 1和max = @ 2

并查看dr.HasRows是否为true返回true(dr是DataReader的对象)



oR





使用SQl查询中存在

使用详细信息的链接是



http ://msdn.microsoft.com/en-us/library/ms188336.aspx [ ^ ]





使用您喜欢的任何选项



最好的运气!!
use 2 parameters in sqlcommand object for min and max entered by user
create datareader to run query select * from tab where min=@1 and max=@2
and see if dr.HasRows return true for simple (dr is object of DataReader)

oR


use exists in SQl query
the link for using details is

http://msdn.microsoft.com/en-us/library/ms188336.aspx[^]


use any option you prefer

Best of Luck!!


可以使用以下查询找到重叠:

The overlap can be find using the following query:
IF EXISTS (SELECT 1 FROM ODRange WHERE 31 <= maximum AND 37 >= Minimum)
  print 'Overlaps'
ELSE
  print 'Does not overlap'





- 阿米特




以下将解决您的目的..



Hi,
Following will solve your purpose..

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中插入正确的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆