Combine CHARINDEX with substring : CHARINDEX « String Functions « SQL Server / T-SQL






Combine CHARINDEX with substring


1>
2> DECLARE @FullName VarChar(25)
3> SET @FullName = 'www.java2s.com'
4> 
5> SELECT SUBSTRING(@FullName, 1,CHARINDEX('java2s', @FullName) - 1)
6> 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.CHARINDEX: Get index of the delimiting space