根据分隔符解析列值
这是我的数据示例:
ABC*12345ABC
BCD*234()
CDE*3456789(&(&
DEF*4567A*B*C
使用 SQL Server 2008 或 SSIS,我需要解析此数据并返回以下结果:
12345
234
3456789
4567
如您所见,星号 (*) 是我的第一个分隔符。第二个“分隔符”(我宽松地使用这个术语)是当数字序列停止时。
所以,基本上,只需抓住星号后面的数字序列......
我怎样才能做到这一点?
编辑:
我在原来的帖子中犯了一个错误。另一个可能值的示例是:
XWZ*A12345%$%
在这种情况下,我想返回以下内容:
A12345
该值可以以字母字符开始,但始终以数字结束。因此,抓住星号后面的所有内容,但停在序列中的最后一个数字上。
任何对此的帮助将不胜感激!
Here is a sample of my data:
ABC*12345ABC
BCD*234()
CDE*3456789(&(&
DEF*4567A*B*C
Using SQL Server 2008 or SSIS, I need to parse this data and return the following result:
12345
234
3456789
4567
As you can see, the asterisk (*) is my first delimiter. The second "delimiter" (I use this term loosely) is when the sequence of numbers STOP.
So, basically, just grab the sequence of numbers after the asterisk...
How can I accomplish this?
EDIT:
I made a mistake in my original post. An example of another possible value would be:
XWZ*A12345%$%
In this case, I would like to return the following:
A12345
The value can START with an alpha character, but it will always END with a number. So, grab everything after the asterisk, but stop at the last number in the sequence.
Any help with this will be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用一点
patindex
和charindex
技巧来做到这一点,例如:这会打印:
You could do this with a little
patindex
andcharindex
trickery, like:This prints:
如果您忽略这是在 SQL 中,那么首先想到的是 Regex:
那里的捕获组应该得到您想要的内容。我不知道SQL是否有正则表达式功能。
If you ignore that this is in SQL then the first thing that comes to mind is Regex:
The capture group there should get what you want. I don't know if SQL has a regex function.