Sql server 如何从中提取“stackoverflow.com”?

Sql server 如何从中提取“stackoverflow.com”?,sql-server,regex,replace,find,Sql Server,Regex,Replace,Find,在SQL Server中,我有一个表名URL\u DATA,其中包含两列域和URL。列URL包含不同站点的地址,例如https://stackoverflow.com/questions/ask. 如何从中提取stackoverflow.com?或者如何在新列域中复制字符串stackoverflow.com Input Table: | Domain | URL | | ------ | ----

在SQL Server中,我有一个表名URL\u DATA,其中包含两列域和URL。列URL包含不同站点的地址,例如https://stackoverflow.com/questions/ask. 如何从中提取stackoverflow.com?或者如何在新列域中复制字符串stackoverflow.com

Input Table:

| Domain |                      URL                             |
| ------ | ---------------------------------------------------- |
|        | https://www.youtube.com/                             |
|        | https://www.youtube.com/feed/library                 |
|        | https://www.red-gate.com/simple-talk/sql/sql-training|
|        | https://internshala.com/student/dashboard            |
|        | https://stackoverflow.com/questions/ask              |

Expected Output Table:

| Domain            |                      URL                             |
| ----------------- | ---------------------------------------------------- |
| youtube.com       | https://www.youtube.com/                             |
| youtube.com       | https://www.youtube.com/feed/library                 |
| red-gate.com      | https://www.red-gate.com/simple-talk/sql/sql-training|
| internshala.com   | https://internshala.com/student/dashboard            |
| stackoverflow.com | https://stackoverflow.com/questions/ask              |
     
我已经厌倦了使用这个:

更新URL_数据集域=replacedomain,,'https://','www


但无法删除尾随字符。

我尝试使用此选项,但效果良好

声明@N2 VARCHAR255; 声明@N1 INT; 从URL_数据中为选择域声明C1游标; 开放式C1 从C1取下一个到@N2 而@@FETCH\u STATUS=0 开始 更新URL\u数据集域=REPLACEREPLACEREPLACE@N2,'http://','https://','www',其中C1的当前值 从C1取下一个到@N2 终止 关闭C1 开放式C1 从C1取下一个到@N2 而@@FETCH\u STATUS=0 开始 设置@N1=CHARINDEX'/',@N2 如果@N1>0 开始 更新URL\u数据集域=SUBSTRING@N2,1,ABSCHARINDEX'/',@N2-1,其中C1的电流 终止 从C1取下一个到@N2 终止 关闭C1
解除分配C1

SQL Server不支持正则表达式;不过,至少不是在本机上,您可以使用CLR函数。然而,一个例子并不足以让我们真正给出答案。充其量,我建议找到第三个正斜杠的位置/并返回那么多的左字符。但这假设每个值都以http://or开头https://.Please 通过显示几个URL示例以及所需的输出,重新表述您的问题。