CHARINDEX: Get index of the delimiting space : CHARINDEX « String Functions « SQL Server / T-SQL






CHARINDEX: Get index of the delimiting space


1> DECLARE @FullName VarChar(25), @SpaceIndex TinyInt
2> SET @FullName = 'www.java2s.com'
3>
4> -- Get index of the delimiting space:
5> SET @SpaceIndex = CHARINDEX('java', @FullName)
6> -- Return all characters to the left of the space:
7> SELECT LEFT(@FullName, @SpaceIndex - 1)
8> GO

-------------------------
www.

(1 rows affected)
1>
           
       








Related examples in the same category

1.CHARINDEX: returns the starting point of the first occurrence of one string of characters within another string
2.CHARINDEX(): find the first occurrence of a substring within another string
3.CHARINDEX('Mars', 'The stars near Mars are far from ours')
4.Combine CHARINDEX with substring