Question: I have the following string:

```
declare @Request varchar(255)
set @Request= '**URGENT** Apple / Iphone/ Test/Future Resolution/Approved'

```

Using an SQL query, how do I return just the word 'Apple'?

I've tried something like this but it does not work:

```
select substring(@Request,CharIndex('** ',@Request),charindex(' / ',@Request))

```

Thank you so much for your input,

Lori

Answer: 
Try this:

```
select SUBSTRING(@request, CHARINDEX('Apple', @Request, 0), LEN('Apple'))

```

If Apple is just an example, and you need a dynamic one, try this:

```
select SUBSTRING(@request, CHARINDEX('** ', @Request, 0)+3, CHARINDEX(' / ', @Request, 0)-CHARINDEX('** ', @Request, 0)-3)

```
You have a few issues here. Firstly the third param of substring is the LENGTH of the substring, not the final index.
Secondly, you aren't taking into account the length of the initial search string '\*\* ' is three chars, and charindex returns the START position of the string.
This will do what you need:

```
declare @Request varchar(255)
set @Request= '**URGENT** Apple / Iphone/ Test/Future Resolution/Approved'

select substring(@Request,charindex('** ',@Request) + 3, charIndex(' /',@Request) - charindex('** ',@Request)- 3)

```

Hence the use of +-3 above