I would like to get a substring 403162 from the given string Praveen(403162) in sql?
You can do it like this:
DECLARE @searchString NVARCHAR(20) = 'Praveen(403162)'
DECLARE @startFrom INT= CHARINDEX('(',@searchstring) + 1
DECLARE @length INT = CHARINDEX(')',@searchstring) - @startFrom
SELECT SUBSTRING(@searchstring,@startFrom, @length) AS RESULT
If you want to do this in one line:
DECLARE @searchString NVARCHAR(20) = 'Praveen(403162)'
SELECT SUBSTRING(@searchstring,
CHARINDEX('(',@searchstring) + 1,
CHARINDEX(')',@searchstring) - CHARINDEX('(',@searchstring) - 1) AS RESULT