-- 左起 第10个逗号之前的字符串,右起 第10个逗号之后的字符串,如何截取长度不一致的字符串?
; with t as (
select '[4],[5],[7],[17],[18],[31],[35],[36],[45],[47],[54],[60]'as notext
UNION ALL SELECT '[1],[2],[3],[4],[5],[6],[7],[8],[9],[46],[48],[49],[51],[53],[54],[58]'
)
select left(notext,charindex(',',notext)+42)as FN_10,right(notext,charindex(',',notext)+40)AS BN_10 from t where charindex(',',notext)+42 > 0
-- 错误的结果
FN_10 BN_10
[4],[5],[7],[17],[18],[31],[35],[36],[45],[47] [17],[18],[31],[35],[36],[45],[47],[54],[60]
[1],[2],[3],[4],[5],[6],[7],[8],[9],[46],[48], ],[8],[9],[46],[48],[49],[51],[53],[54],[58]
想要的结果
FN_10 BN_10
[4],[5],[7],[17],[18],[31],[35],[36],[45],[47] [7],[17],[18],[31],[35],[36],[45],[47],[54],[60]
[1],[2],[3],[4],[5],[6],[7],[8],[9],[46] [7],[8],[9],[46],[48],[49],[51],[53],[54],[58]