sql 字段分割函数 + 查询
结果:
用于解决 这种 字段的查询
1.先创建分割函数 => 复制到数据库直接执行
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
by kudychen 2011-9-28
*/
CREATE function [dbo].[SplitNum]
(
@Input nvarchar(max), --input string to be separated
@Separator nvarchar(max)=',', --a string that delimit the substrings in the input string
@RemoveEmptyEntries bit=1 --the return value does not include array elements that contain an empty string
)
returns @TABLE table
(
[Id] int identity(1,1),
[Value] nvarchar(max)
)
as
begin
declare @Index int, @Entry nvarchar(max)
set @Index = charindex(@Separator,@Input)
while (@Index>0)
begin
set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1)))
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
begin
insert into @TABLE([Value]) Values(@Entry)
end
set @Input = substring(@Input, @Index+datalength(@Separator)/2, len(@Input))
set @Index = charindex(@Separator, @Input)
end
set @Entry=ltrim(rtrim(@Input))
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
begin
insert into @TABLE([Value]) Values(@Entry)
end
return
end
2.查询 =>自己替换表
SplitNum=>函数,
Value=> 要查询的值
----------------------------------
select * from 表 where id
in
(
select distinct ad.adid from (select a.id adid,recrid.Id,recrid.Value from 表 a outer apply SplitNum(a.expirationdate,',',2) recrid ) ad where ad.Value=15
)
最新文章
- Bzoj3524 [Poi2014]Couriers
- PHP mkdir()无写权限的问题解决方法
- Effective C++ -----条款05:了解C++默默编写并调用哪些函数
- Java编程思想学习(十二) 数组和容器
- JVM总结
- apache 配置order allow deny讲解
- Atitit.Gui控件and面板----web server区----- web服务器监控面板and控制台条目
- Linux与JVM的内存关系分析(转)
- 【HighCharts系列教程】六、去除highCharts版权信息的几种方法
- VB.NET中的常用方法
- Ubuntu16.04 install OpenJDK8
- js switch 字符串
- nginx配置打印请求响应内容
- css美化滚动条
- 程序中使用now()函数对性能的影响
- 有关g++的Xlinker选项
- tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别
- 对于“机器视觉(computer version)”的反思
- [DeeplearningAI笔记]序列模型2.10词嵌入除偏
- shell kill session
热门文章
- C#DataTableRow列值互转
- 【学习日志】MongoDB为什么选择B树,而MySQL选择B+树实现索引
- spring in action day07 RabbitMq
- Sentinel入门到实操 (限流熔断降级)
- 4.12 疫情数据可视化 毕设(初稿版 crud+可视化echarts
- 毕设进度更新(真的不知道自己做到哪- - 备忘录性质)+3.19是mavan配置的常见问题
- 学习Java Day30
- 如何使用 ArrayPool
- Java7.10
- 鼎阳SDS6204示波器的EPICS IOC调试