tags:

views:

21

answers:

3

Hi folks,

i've got some string in some sql. i need to find out what the character is, for that string, given a index.

eg.

DECLARE @someString NVARCHAR(MAX) = 'hi folks'
DECLARE @index INT = 4 -- assuming the first index is 1, not 0.

now .. how do i get the character at 4th index slot, which is an 'f', in that example above.

thanks :)

+1  A: 

Use the SUBSTRING function.

SUBSTRING ( value_expression ,start_expression , length_expression )

SELECT SUBSTRING ( @someString, @index, 1);
Yada
+1  A: 

You can try

DECLARE @someString NVARCHAR(MAX) = 'hi folks' 
DECLARE @index INT = 4 -- assuming the first index is 1, not 0.
SELECT SUBSTRING(@someString, @index, 1)
astander
+1  A: 

Use SUBSTRING:

SELECT SUBSTRING(@someString, @index, 1)
OMG Ponies