查询某个数在该数组中是否存在-函数
来源:互联网 发布:上海高达软件 编辑:程序博客网 时间:2024/05/17 23:39
create function myaaaa1--查询某个数在该数组中是否存在
(
@a varchar(200), --数组
@i int --数字
)
returns int
as
begin
declare @result int;--结果
declare @left varchar(200);--,号左边数组
declare @h_left int;--左边数字——
declare @h_right int;
set @result=0;
while charindex(',',@a)>0--循环语句
begin
set @left=left(@a,charindex(',',@a)-1)
if charindex('-',@left)>0
begin--myaaaa
set @h_left=left(@left,charindex('-',@left)-1)
set @h_right=right(@left,len(@left)-charindex('-',@left))
select @result=case when @i>@h_left-1 and @i<@h_right+1 then @result+1
else @result end
end
else
begin
select @result=case when convert(int,@left)=@i then @result+1 else @result end;
end
set @a=right(@a,len(@a)-charindex(',',@a));
end
if charindex('-',@a)>0
begin--myaaaa
set @h_left=left(@a,charindex('-',@a)-1)
set @h_right=right(@a,len(@a)-charindex('-',@a))
select @result=case when @i>@h_left-1 and @i<@h_right+1 then @result+1
else @result end
end
else
begin
select @result=case when convert(int,@a)=@i then @result+1 else @result end;
end
return @result;
select dbo.myaaaa1('1,3-6',4)
select dbo.myaaaa1('3,9-12',4)
select dbo.myaaaa1('1,3-6,9-12',4)
(
@a varchar(200), --数组
@i int --数字
)
returns int
as
begin
declare @result int;--结果
declare @left varchar(200);--,号左边数组
declare @h_left int;--左边数字——
declare @h_right int;
set @result=0;
while charindex(',',@a)>0--循环语句
begin
set @left=left(@a,charindex(',',@a)-1)
if charindex('-',@left)>0
begin--myaaaa
set @h_left=left(@left,charindex('-',@left)-1)
set @h_right=right(@left,len(@left)-charindex('-',@left))
select @result=case when @i>@h_left-1 and @i<@h_right+1 then @result+1
else @result end
end
else
begin
select @result=case when convert(int,@left)=@i then @result+1 else @result end;
end
set @a=right(@a,len(@a)-charindex(',',@a));
end
if charindex('-',@a)>0
begin--myaaaa
set @h_left=left(@a,charindex('-',@a)-1)
set @h_right=right(@a,len(@a)-charindex('-',@a))
select @result=case when @i>@h_left-1 and @i<@h_right+1 then @result+1
else @result end
end
else
begin
select @result=case when convert(int,@a)=@i then @result+1 else @result end;
end
return @result;
end
select dbo.myaaaa1('4',4)
select dbo.myaaaa1('01,02,03,05,06,07,08,09,10,11,12,13,14,15,16',4)
select dbo.myaaaa1('1,3-6',4)
select dbo.myaaaa1('3,9-12',4)
select dbo.myaaaa1('1,3-6,9-12',4)
select dbo.myaaaa1('3,5-6,9-12',4)
嘻嘻,小有得瑟。
- 查询某个数在该数组中是否存在-函数
- 二维数组中查找某个数是否存在
- 循环递增数组中查找是否存在某个数
- java 判断二维数组中是否存在某个数
- js查询数组中是否存在某个值
- javascript中检测某个字符串在数组中是否存在
- 查询一个数是否在数组中?
- mysql FIND_IN_SET查询 字段,拼接数据是否存在某个值 in查询字段存在某个数组中
- 查询数据库中某个元素是否存在
- sql中查询某个表是否存在
- JAVA查找该数是否在数组中
- 检查数组中是否存在某个值 php-数组函数in_array()
- php数组学习之in_array() 函数查找数组中是否存在某个值
- 检查数组中是否存在某个值 php-数组函数in_array()
- :输入10个整数,保存在一个数组中,在数组中查找某个数,给出是否找到的信息。如果找到了,要求输出该数在数组中所处的位置;如果找不到,输出“没有找到!
- PHP判断某个数组中是否存在指定的key,函数array_key_exists()
- PHP 判断二维数组中是否存在某个数组
- php中查找数组中是否存在某个元素
- 尚学堂_马士兵_oracle_笔记
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- 剖析SQL Server 2005查询通知之基础篇(3)
- HALCON算子函数——Chapter 4 : File
- android学习网址
- 查询某个数在该数组中是否存在-函数
- centos删除多余内核启动项
- oracle表空间操作详解
- com组件和一般dll的区别
- HALCON算子函数——Chapter 5 : Filter
- JavaScript定时器演示
- AutoCompleteTextView获取其内容
- web应用程序中的rootkit
- 怎样释放获取到的ip地址及重新获取