-2

How can I get specific char in string, between char space and 'IU' like this:

BEMFOLA 225IU/0,375ML
BEMFOLA 300IU/0,5ML

Result:

225
300
jarlh
  • 42,561
  • 8
  • 45
  • 63
Hans33
  • 19
  • 1
  • 4
  • `SUBSTRING ( expression ,start , length ) ` [https://learn.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=aps-pdw-2016](https://learn.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=aps-pdw-2016) – Kagiso Marvin Molekwa Nov 07 '18 at 14:02

1 Answers1

1

Here is one method with charindex and substring

declare @var varchar(16) = 'BEMFOLA 225IU/0,375ML'

select SUBSTRING(@var,charindex(' ',@var),charindex('IU',@var) - charindex(' ',@var))

If IU can be any two characters, then you can use:

select SUBSTRING(@var,charindex(' ',@var),charindex('/',@var) - charindex(' ',@var) - 2)

This takes the substring of your string from the first space, to two places before the slash.

S3S
  • 24,809
  • 5
  • 26
  • 45