下面是文本,我想在Sql中仅返回双引号中的数据。
输入 -
Task "Testing Data" started successfully.
输出:
Testing Data
答案 0 :(得分:2)
尝试以下。
DECLARE @testData VARCHAR(100) = 'Task : "Testing Data" started successfully.'
SELECT Substring(@testData, Charindex('"', @testData, 1) + 1,
Len(@testData) - Charindex('"', @testData) -
Charindex('"', Reverse(@testData))) AS [Output];
<强>输出强>
+--------------+
| Output |
+--------------+
| Testing Data |
+--------------+
答案 1 :(得分:0)
<强> MYsql的强>
SELECT replace(SUBSTRING_INDEX
('"Testing Data" started successfully.', '"', 2),'"','')
<强> SQLServer的强>
select replace(substring(@string,1,charindex('"',@string,2)),'"','')
答案 2 :(得分:0)
请使用:
DECLARE @Text varchar(100) = 'Task : "Testing Data" started successfully.'
SELECT SUBSTRING(@Text,CHARINDEX('"',@Text)+1, CHARINDEX('"',@Text,CHARINDEX('"',@Text)+1)-CHARINDEX('"',@Text)-1)
答案 3 :(得分:0)
在mySQL中试试这个:
set @myVar = 'Task : "Testing Data" started successfully';
select substring_index(substring_index(@myVar, '"', -2),'"',1)
答案 4 :(得分:0)
MS SQL SERVER
-
我使用substring
,charindex
,patindex
和iif
函数来解决此问题。请在下面找到我的查询 -
declare @tmp_tbl table (id int identity, Some_string nvarchar(1000))
insert into @tmp_tbl (Some_string)
select '"Testing Data" example' union all
select 'Test data "Testing Data"' union all
select 'Test "Testing Data" example' union all
select 'Test example' union all
select 'Test " example' union all
select 'Test "" example' union all
select 'Test "Testing Data" example "Testing 123 '
select
id,
iif(
patindex('%"%"%', Some_string) = 0,
NULL,
substring(
Some_string,
(charindex('"', Some_string) + 1),
charindex('"', Some_string, charindex('"', Some_string) + 1) - charindex('"', Some_string) - 1
)
)
from
@tmp_tbl