简体   繁体   English

从长字符串的中间提取字符串 - SQL

[英]Extract a string from the middle of a long string - SQL

I have a table which has a column with a long string, i'm tasked with parsing an ID from the string, i've gotten to the point where I can extract everything after a delimiter string, but my query is still catching everything after the delimiter string, which I don't need.我有一个表,其中有一列长字符串,我的任务是从字符串中解析一个 ID,我已经到了可以在分隔符字符串之后提取所有内容的地步,但我的查询仍在捕获之后的所有内容分隔符字符串,我不需要。

There are records where have multiple ID's on the same line that I need to separate and capture as well.有些记录在同一行上有多个 ID,我也需要分开和捕获。

I've included the SQL fiddle:我已经包含了 SQL 小提琴:

fiddle小提琴

For some reason on the live data, when I use the query I have provided, it doesn't always capture the account number.由于实时数据的某种原因,当我使用我提供的查询时,它并不总是捕获帐号。

Here is an updated SQL Fiddle to show the new problems I'm running into.这是一个更新的 SQL Fiddle 来显示我遇到的新问题。 Updated FIDDLE更新的小提琴

This returns the account numbers in the data:这将返回数据中的帐号:

select s.value
from temp t CROSS APPLY
     (VALUES (STUFF(description, 1, CHARINDEX('Account Attached: ', description) + LEN('Account Attached: '), '')
             )
     ) v(aa) CROSS APPLY
     STRING_SPLIT(LEFT(v.aa, CHARINDEX('Next Steps:', v.aa) - 2), ' ') s;

Here is your SQL Fiddle.是您的 SQL Fiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM