Using T-SQL, return nth delimited element from a string

后端 未结 11 1103
半阙折子戏
半阙折子戏 2020-11-22 14:45

I have a need to create a function the will return nth element of a delimited string.

For a data migration project, I am converting JSON audit records stored in a S

11条回答
  •  被撕碎了的回忆
    2020-11-22 15:17

    I don't have enough reputation to comment, so I am adding an answer. Please adjust as appropriate.

    I have a problem with Gary Kindel's answer for cases where there is nothing between the two delimiters

    If you do select * from dbo.GetSplitString_CTE('abc^def^^ghi','^',3) you get ghi instead of an empty string

    If you comment out the WHERE LEN([value]) > 0 line, you get the desired result

提交回复
热议问题