使用LEFT
,RIGHT
和CHARINDEX
作爲;
declare @start varchar(50)='{strong}', @end varchar(50)='{/strong}'
select @var2 = left(@var1,charindex(@end,@var1,1)+len(@end)),
@var1= right(@var1,len(@var1)-(charindex(@end,@var1,1)+len(@end)))
SQL DEMO 1
這是有點瘋狂,但通用和一些文字before '{strong}' tag
也有效。
declare
@var1 varchar(100)= 'front text{strong} this is strong{/strong} this is not strong',
@var2 varchar(100)= ''
declare @start varchar(50)='{strong}', @end varchar(50)='{/strong}'
select @var2 = substring(myString,ci1,ci2+len(@end)-ci1),
@var1 = right(myString,len(myString) - (ci2+ len(@end)))
from (
select @var1 myString, charindex(@start,@var1,1) ci1,
charindex(@end,@var1,charindex(@start,@var1,1)) ci2
) T
select @var2 var2 ,@var1 var1
SQL DEMO 2
--Results
VAR2 VAR1
{strong} this is strong{/strong} this is not strong
來源
2013-01-31 10:30:49
Kaf
數據庫? (我懷疑MS SQL Server,但仍然) –
你爲什麼使用SQL標籤? – Steve
沒有強是隻是一個字沒有具體的字符串是MS SQL DB – SalemRady