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 查找指定字符串的位置的更多相关文章

  1. sql server 查找包含字符串的对象

    sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...

  2. SQL server查找指定表的所有索引

    WITH tmp AS ( SELECT indexname = a.name , tablename = c.name , indexcolumns = d.name , a.indid FROM ...

  3. SQL Server中截取字符串常用函数

    SQL Server 中截取字符串常用的函数: .LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要截 ...

  4. SQL Server 中截取字符串常用的函数

    SQL Server 中截取字符串常用的函数: 1.LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要 ...

  5. sql server中截取字符串的常用函数

    我们如果要在sql server中,使用截取字符串的方法要怎样使用呢? sql server提供了3个常用截取字符串方法,LEFT().RIGHT().SUBSTRING() /****** Sql ...

  6. SQL SERVER 2012 修改数据库默认位置不立即生效

    今天修改SQL SERVER 2012的数据库默认位置:即数据文件.日志文件默认位置时遇到一个问题,单击"服务器属性"(Server Properties)--> 数据库设置 ...

  7. SQL Server获取指定行的数据

    SQL Server获取指定行(如第二行)的数据   --SQL Server获取指定行(如第二行)的数据-- --法一(对象法)-- select * from ( select * , numbe ...

  8. Sql Server系列:字符串函数

    字符串函数用于对字符和二进制字符串进行各种操作,大多数字符串函数只能作用于char.nchar.varchar和nvarchar数据类型.字符串函数可以用在SELECT或者WHERE语句中. 1. A ...

  9. SQL Server(第二章) 字符串函数、日期时间函数、转换函数

    --1.CONCAT 函数:字符串连接(支持sql server2012 SQL规则 如果与NULL连接返回NILL) SELECT empid,CONCAT(firstname,lastname) ...

随机推荐

  1. pyenv简介——Debian/Ubuntu中管理多版本Python

    pyenv简介——Debian/Ubuntu中管理多版本Python MAY 21ST, 2016 12:00 AM | COMMENTS pyenv是管理Python版本的工具,它支持在多个Pyth ...

  2. uva 10026 Problem C: Edit Step Ladders

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. U8800安装软件显示无效的URI问题

    看到很多人遇到这个问题,其中包括我自己,最后找到可行的解决办法,现整理出来一个新帖,有同样问题的U友可以参考下. 手机先连接电脑,进入USB存储状态,然后在计算机上找到SD卡目录下的.android_ ...

  4. 再看C

    1. clrscr(void) 清屏 clear screen;gotoxy(x,y); 移动光标至指定位置;

  5. 模拟Vue之数据驱动2

    一.前言 在随笔“模拟Vue之数据驱动1”结尾处,我们说到如果监听的属性是个对象呢?那么这个对象中的其他属性岂不就是监听不了了吗? 如下: 倘若user中的name.age属性变化,如何知道它们变化了 ...

  6. JS浏览器对象-Screen对象

    代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  7. C#_Test

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Plus ...

  8. Ajax请求用户控件(.ascx)404错误

  9. jquery 滚动条 scroll 和 animate出现的问题总结

    这两天刚刚学习了jquery就想把平时做看到的一些相关效果用新的知识写写看.知识平时看着都懂,实际操作中问题才会层出不穷. <!DOCTYPE html> <html> < ...

  10. 设置应用中出现NFC服务,去掉

    还可以在 里面修改