在SQL Server查询中获得两个字符之间的子字符串
我想在以下字符串中获取两个字符之间的字符串:
hello @user1, how are you?
我想在@
和 space
之间获取文本,@
哪些导致 user1
,有没有办法做到这一点?甚至可能有2个或更多 @
我需要像
hello @user1 ,@user2 ,@... , how are you?
在这里提取的那样提取的是一个类似桌子的示例:
示例 | 删除的输出 |
---|---|
helly @user1和 @user2你好吗? | user1,user2 |
@user1和 @user2回复了 | user1,user2, |
但是在每个 @
之后,总会有一个 space
。
感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常的接近方法将是
string_split()
和string_agg()
的组合:请参见工作小提琴
根据要求,一种可能的替代方法来确保字符串元素的订购元素如下;此方法使用 json阵列提供订购阵列索引:
注:此替代小提琴您可以使用 desc 关键字来逆转订购或字符串。
The usual way to approach would be a combination of
String_Split()
andString_Agg()
:See Working fiddle
As requested, a possible alternative approach to ensure the ordering of the string elements is as follows; this method uses a json array that provides the array index for ordering:
Note from this alternative Fiddle you can reverse the ordering or the strings using the desc keyword.