从字符串中查询Pershing子字符串的SQL

时间:2015-04-03 13:05:04

标签: sql sql-server

1>

a:2{s:8:"folderid";s:28:"0B2cFhOMCK2KEOVBzbnZOczZsNkU";s:10:
"foldertext";s:17:"Home Health Files";}

2 - ;

a:2{s:8:"folderid";s:28:"0B2cFhOMCK2KEOVBzbnZOczZsNkU";s:10:
"foldertext";s:12:"Agency Files";}

3>

  a:2{s:8:"folderid";s:28:"0B2cFhOMCK2KEMVB4SGFtVmozamc";s:10:"foldertext";s:9:"Dover HHC";}

我需要上述字符串中的文件夹名称,即Home Health FilesAgency FilesDover HHC

,最后一个用""括起来的子字符串;

1 个答案:

答案 0 :(得分:1)

试试这个:

DECLARE @role VARCHAR(4000) = 'a:2{s:8:"folderid";s:28:"0B2cFhOMCK2KEOVBzbnZOczZsNkU";s:10:"foldertext";s:17:"Home Health Files";}'
SELECT SUBSTRING(@role,LEN(@role)-CHARINDEX('"',REVERSE(@role),CHARINDEX('"',REVERSE(@role),0)+1)+2,(LEN(@role)-CHARINDEX('"',REVERSE(@role),0)-1)-(LEN(@role)-CHARINDEX('"',REVERSE(@role),CHARINDEX('"',REVERSE(@role),0)+1)))