Home > database > SQL field interception content problem, need to capture the contents of the location is not fixed
SQL field interception content problem, need to capture the contents of the location is not fixed
Time:11-16
Have a fixed string in field to intercept a content after For example, 1.12345678 id100056 2.1234 id100058 3.234567 id100057 Need to capture specific Numbers after the ID string in each field, fixed digits Hope is the result of the 100056 100058 100057 Access to digital hope and another update association, eligible update numerical Written up step Still need to put a table in the first match
CodePudding user response:
The create table # t (id int, x varchar (50))
Insert into # t (id, x) Select 1, '12345678 id100056' union all Select 2, '1234 id100058' union all Select 3, '234567 id100057'
Select id, x, x2=cast (substring (x, charindex (' id ', x) + 2, 50) as an int) The from # t