[英]SQL server Rex fetch string in wildcard
例如,我有一個帶有表名和模式的字符串:
[dbo].[statistical]
如何僅從該字符串中提取statistical
的表名?
這是PARSENAME
的用途:
SELECT PARSENAME('[dbo].[statistical]', 1)
SELECT PARSENAME('[adventureworks].[dbo].[statistical]', 1)
SELECT PARSENAME('[adventureworks]..[statistical]', 1)
SELECT PARSENAME('[statistical]', 1)
SELECT PARSENAME('dbo.statistical', 1)
-- all examples return 'statistical'
您也可以嘗試以下方法:
declare @s varchar(100) = 'asd.stadfa';
select reverse(substring(s, 1, charindex('.', s) - 1)) from (
select reverse(@s) s
) a
charindex
返回字符的第一個出現位置,因此您反轉初始字符串以使最后一個點優先。 然后,您只需要使用子字符串來提取反向字符串的第一部分,這就是您想要的。 最后,你需要申請reverse
一個更多的時間來扭轉反萃取串:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.