当前位置:首页 > 数据库 > Sqlserver

sqlserver 查找某个字符在字符串中第N次出现的位置

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
第二步:
截取学生第N道题的答案和正确答案第N道题做比较,把做对的人的分数加1。
update dbo.T_dxyysyj_BankedCloze2_Record
set Fraction =Fraction +1
where QuestionID =‘3‘ and SUBSTRING(ExamAnswer,dbo.fn_find(@find,@str,@mystart)+1,@mylength)=SUBSTRING(@str,dbo.fn_find(@find,@str,@mystart)+1,@mylength)
第三步:
封装成存储过程。

版权声明:本文为博主原创文章,未经博主允许不得转载。

sqlserver 查找某个字符在字符串中第N次出现的位置

标签:

本文系统来源:http://blog.csdn.net/cxl0921/article/details/46495125


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐