邹建兄请进!!!!!!!!!!!!!!!!!有事相求

kuaile999 2003-11-18 12:32:03
邹建兄你好:
那天你给我写的那个存储过程,

现在遇到如下问题:
1,如果现在数据是10和40,原题意思9-50也是不行的,但你的算法却可以

2,表tb有三个字段,
id number1 number2
1 10 20
2 21 30
3 31 40
4 41 50

我想在校验时,想把指定的id所在行排除,把存储过程改了一下,没能达到我的要求,应该怎样改呢?
能麻烦你帮我改一下吗?谢谢!!

--创建检测的存储过程
create proc ifCanInsert
@n1 int, --要插入的数值1
@n2 int, --要插入的数值2
@id int, --要排除检测的id
@ifCanInsert bit=null output --检测结果,1表示能插入,0表示不能插入
as
if exists(select 1 from tb where id<>@id @n1 between number1 and number2 or @n2 between number1 and number2)
set @ifCanInsert=0
else
set @ifCanInsert=1
go
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuaile999 2003-11-19
  • 打赏
  • 举报
回复
忘了给大力分了
kuaile999 2003-11-18
  • 打赏
  • 举报
回复
好!
谢谢二位高手!
一人25分
太少了
:)
zjcxc 元老 2003-11-18
  • 打赏
  • 举报
回复
--创建检测的存储过程
create proc ifCanInsert
@n1 int, --要插入的数值1
@n2 int, --要插入的数值2
@id int, --要排除检测的id
@ifCanInsert bit=null output --检测结果,1表示能插入,0表示不能插入
as
declare @n int
if @n1>@n2 select @n=@n1,@n1=@n2,@n2=@n
if exists(select 1 from tb where id<>@id and(number1<@n2 or number2>@n1))
set @ifCanInsert=0
else
set @ifCanInsert=1
go
zjcxc 元老 2003-11-18
  • 打赏
  • 举报
回复
--创建检测的存储过程
create proc ifCanInsert
@n1 int, --要插入的数值1
@n2 int, --要插入的数值2
@id int, --要排除检测的id
@ifCanInsert bit=null output --检测结果,1表示能插入,0表示不能插入
as
declare @n int
if @n1>@n2 select @n=@n1,@n1=@n2,@n2=@n
if exists(select 1 from tb where number1<@n2 or number2>@n1)
set @ifCanInsert=0
else
set @ifCanInsert=1
go
kuaile999 2003-11-18
  • 打赏
  • 举报
回复
惭愧!
揭贴,向高手学习!
pengdali 2003-11-18
  • 打赏
  • 举报
回复
create proc ifCanInsert
@n1 int, --要插入的数值1
@n2 int, --要插入的数值2
@id int, --要排除检测的id
@ifCanInsert bit=null output --检测结果,1表示能插入,0表示不能插入
as
if exists(select 1 from tb where id<>@id and (@n1 between number1 and number2 or @n2 between number1 and number2))
set @ifCanInsert=0
else
set @ifCanInsert=1
go

????

34,495

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧