具有模式匹配的 SQL 新列
我有一个带有 url 字符串的列,如下所示
http://www.somedomain.edu/ rootsite1/某事/某事/ 或者 http://www.somedomain.edu/sites/rootsite2/something/something
基本上我只想将字符串返回到根站点(在另一列中)..根站点可以是任何(除了/sites),但它将遵循/sites/或.edu/,
因此上面的两个字符串将返回:
http://www.somedomain.edu/rootsite1
http://www.somedomain.edu/sites/rootsite2
我不能使用 CLR 编译视图,所以我不认为 Regex 是一个选项。
感谢您的任何帮助。
I have a column with a url sting that looks like this
http://www.somedomain.edu/rootsite1/something/something/
or
http://www.somedomain.edu/sites/rootsite2/something/something
Basically I want to ONLY return the string up to root site (in another column).. root site can be anyting (but /sites), but it will either follow /sites/ or .edu/
so the above two strings would return:
http://www.somedomain.edu/rootsite1
http://www.somedomain.edu/sites/rootsite2
I can't compile the view with CLR, so I don't think Regex is an option.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以通过在客户端拆分 URL 并将其保存为表中的两部分(一个包含“根”站点,另一个包含特定于站点的路径),然后将它们重新组合在一起来做得更好检索后在客户端。
如果您选择将它们存储在如上所述的表中,则可以使用
CHARINDEX
来确定.edu
或/sites/
出现的位置在字符串中,然后使用SUBSTRING
根据该索引将其分解。如果您确实需要这样做,这里有一个示例:
I think you'll do better by splitting up the URL on the client side and saving it as two pieces in the table (one containing the "root" site, the other containing the site-specific path), then putting them back together again on the client side after retrieval.
If you choose to store them in the table as you describe above, you can use
CHARINDEX
to determine where the.edu
or/sites/
occurs in the string, then useSUBSTRING
to break it up based on that index.If you really need to do this, here's an example:
你可以使用 CHARINDEX、LEN 和 SUBSTRING 来执行此操作,尽管我不确定 sql 是执行此操作的最佳位置,
这不是一个完整的解决方案,但应该给你一个开始
you could use CHARINDEX, LEN and SUBSTRING to do this although im not sure sql is the best place to do it
Not a full solution but should give you a start