/*
Returns the nth character of a string with a specific delimiter.
*/
-- Select DBO. getsplit ('a: B: C: D: e', ':', 2)
Create Function getsplit (@ nvsourcesql nvarchar (4000), @ strseprate varchar (10), @ IPOs INT)
Returns varchar (100)
-- Implement the nth character split function to get a string with a specific delimiter
-- Date: 2006-05-26
-- Author: xw_cai
As
Begin
Declare @ I int, @ vreturnvalue varchar (100)
, @ Istrcount int
Select @ nvsourcesql = rtrim (ltrim (@ nvsourcesql ))
, @ I = charindex (@ strseprate, @ nvsourcesql)
, @ Vreturnvalue =''
, @ Istrcount = Len (LEN (@ nvsourcesql)-len (replace (@ nvsourcesql, @ strseprate, '') + 1
If (@ istrcount <@ IPOS) -- returns a null value when the number of characters entered exceeds the range.
Begin
Return''
End
If (right (@ nvsourcesql, 1) <> @ strseprate)
Begin
Set @ nvsourcesql = @ nvsourcesql + @ strseprate
End
While @ IPOs> = 1
Begin
Set @ vreturnvalue = left (@ nvsourcesql, @ i-1)
Set @ nvsourcesql = substring (@ nvsourcesql, @ I + 1, Len (@ nvsourcesql)-@ I)
Set @ I = charindex (@ strseprate, @ nvsourcesql)
Set @ IPOs =@iPos-1
End
Return @ vreturnvalue
End