sql server 查找指定字符串的位置
create function fn_find(@find varchar(8000), @str varchar(8000), @n smallint)
returns int
as
begin
if @n < 1 return (0)
declare @start smallint, @count smallint, @index smallint, @len smallint
set @index = charindex(@find, @str)
if @index = 0 return (0)
else select @count = 1, @len = len(@find)
while @index > 0 and @count < @n
begin
set @start = @index + @len
select @index = charindex(@find, @str, @start), @count = @count + 1
end
if @count < @n set @index = 0
return (@index)
end
go declare @str varchar(100)
set @str='A,B,C,D,A,B,C,D,C,D,B,A,C,E' select dbo.fn_find('A',@str,1) as one, dbo.fn_find('A',@str,2) as two, dbo.fn_find('A',@str,3) as three, dbo.fn_find('A',@str,4) as four
/*
one two three four
----------- ----------- ----------- -----------
1 9 23 0
*/
sql server 查找指定字符串的位置的更多相关文章
- sql server 查找包含字符串的对象
sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...
- SQL server查找指定表的所有索引
WITH tmp AS ( SELECT indexname = a.name , tablename = c.name , indexcolumns = d.name , a.indid FROM ...
- SQL Server中截取字符串常用函数
SQL Server 中截取字符串常用的函数: .LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要截 ...
- SQL Server 中截取字符串常用的函数
SQL Server 中截取字符串常用的函数: 1.LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要 ...
- sql server中截取字符串的常用函数
我们如果要在sql server中,使用截取字符串的方法要怎样使用呢? sql server提供了3个常用截取字符串方法,LEFT().RIGHT().SUBSTRING() /****** Sql ...
- SQL SERVER 2012 修改数据库默认位置不立即生效
今天修改SQL SERVER 2012的数据库默认位置:即数据文件.日志文件默认位置时遇到一个问题,单击"服务器属性"(Server Properties)--> 数据库设置 ...
- SQL Server获取指定行的数据
SQL Server获取指定行(如第二行)的数据 --SQL Server获取指定行(如第二行)的数据-- --法一(对象法)-- select * from ( select * , numbe ...
- Sql Server系列:字符串函数
字符串函数用于对字符和二进制字符串进行各种操作,大多数字符串函数只能作用于char.nchar.varchar和nvarchar数据类型.字符串函数可以用在SELECT或者WHERE语句中. 1. A ...
- SQL Server(第二章) 字符串函数、日期时间函数、转换函数
--1.CONCAT 函数:字符串连接(支持sql server2012 SQL规则 如果与NULL连接返回NILL) SELECT empid,CONCAT(firstname,lastname) ...
随机推荐
- MFC自创建类了解
CxxxxView 视窗类 所有的按键 等消息都先在这里响应 CxxxxDoc 文档类 CMainFrame 框架类 CxxxxApp 应用程序类 CxxxxView类中的 OnDraw函数 在窗口改 ...
- SVM的点滴
SVM 1. 普通SVM的分类函数可表示为: 其中ai为待优化参数,物理意义即为支持向量样本权重,yi用来表示训练样本属性,正样本或者负样本,为计算内积的核函数,b为待优化参数. 其优化目标函数为: ...
- shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹
shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...
- WINDOWS基本数据类型示例
最近也学学这些,争取把所有东东都串起来. #include <Windows.h> #include <stdio.h> int WINAPI WinMain( HINSTAN ...
- Smarty 插件开发
插件包含了: functions modifiers block functions compiler functions prefilters postfilters outputfilters r ...
- 【转】你应该知道的 10 个 VirtualBox 技巧与高级特性
原文网址:http://www.oschina.net/translate/10-virtualbox-tricks-and-advanced-features-you-should-know-abo ...
- 用 O(1) 时间检测整数 n 是否是 2 的幂次。
位操作 2的幂次数 2 10 4 100 8 1000 16 10000 ... 1 class Solution { 2 /* 3 * @param n: An integer 4 * @retu ...
- POJ1741--Tree (树的点分治) 求树上距离小于等于k的点对数
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12276 Accepted: 3886 Description ...
- C++Memset误区
Memset的原型是void *memset(void *s, char ch, size_t n); Memset是按字节赋值的,对char以外的类型赋0(00000000) -1(11111111 ...
- flume-agent实例
flume 多种适配,多样化的数据收集 核心概念 event:一条消息 client:访问者 agent: 重要组件Sour ...