我有一个包含评论的专栏。我需要在两个已知单词之间用子串表示值。SQL

我有一个包含评论的专栏。我需要在两个已知单词之间用子串表示值。SQL,sql,tsql,Sql,Tsql,比如说 第一个知道的是发生日期:下一个单词是类型。 发生日期:2013年10月14日类型:药师xyz 在本例中,我需要2013年10月14日的日期 这是我目前掌握的代码 substring(shortnote,charindex('occurance date:', shortnote),charindex('type',shortnote) - charindex('occurance date:', shortnote) -len('type')) 您可以将整个逻辑基于开始模式,并使用PA

比如说 第一个知道的是发生日期:下一个单词是类型。 发生日期:2013年10月14日类型:药师xyz

在本例中,我需要2013年10月14日的日期

这是我目前掌握的代码

substring(shortnote,charindex('occurance date:', shortnote),charindex('type',shortnote) - charindex('occurance date:', shortnote) -len('type'))

您可以将整个逻辑基于开始模式,并使用
PATINDEX
解决此问题

差不多

DECLARE @VAR VARCHAR(100)
SET @VAR='asdfasdfasfasdfasfa asasfd Occurance Date: 10/14/2013 type: drug physician xyz'

DECLARE @Begin_Pattern VARCHAR(100)
SET @Begin_Pattern='Occurance Date: '    

SELECT SUBSTRING(@VAR,(PATINDEX('%Occurance Date: %',@VAR)+LEN(@Begin_Pattern)),11)

我刚试过,效果很好。11是用来干什么的,因为我要用代码来表达相同的想法,但用不同的词。11是日期片中的字符数
LEN('10/24/2013')