Home > database >  Not sure how to intercept length in SQL to a character
Not sure how to intercept length in SQL to a character

Time:10-05



Want to capture the school, how should do? Length of uncertainty in front of the school, the school is not sure

CodePudding user response:

Intercept "graduate" and a comma between the characters

CodePudding user response:

Write a function to deal with, so long as regular

CodePudding user response:

 if not object_id (' school ') is null 
Drop table school
Go
The Create table school ([Student] nvarchar (2), [introduce] nvarchar (100))
Insert school
Select N 'Joe', N 'in 1988, graduated from anhui university of finance and economics' union all
Select N 'Cathy', N '1988 graduated from south China normal university education professional' union all
Select N 'bill', N 'professional graduated from Beijing university in 1988 linguistics'

Select substring (school, 4, charindex (' learn 'school)) as the from school (
Select
The SUBSTRING (introduce, charindex (' graduate, introduce), charindex (' university, introduce) - charindex (' graduate, introduce)) + 'university' as school
The from school) t1
  • Related