this is my string:
lid://abcde.ln.ln_dev_510
how to get the number after '_' using LTRIM, RTRIM.
Thank You.
this is my string:
lid://abcde.ln.ln_dev_510
how to get the number after '_' using LTRIM, RTRIM.
Thank You.
In you case using PARSENAME you can get the values after the last _.
DECLARE @StringValue AS VARCHAR (500) = 'lid://abcde.ln.ln_dev_510';
SELECT PARSENAME(REPLACE(PARSENAME(@StringValue, 1), '_', '.'), 1)
Output will be:
510
At first we REVERSE the string backward to find last occurrence of '_' symbol (since SQL Server got no other way to search for last occurrence of string in another, we need to reverse the string). The number we get minus 1 is exactly number of symbols we must to take from RIGHT part of original string.
DECLARE @str nvarchar(max) = 'lid://abcde.ln.ln_dev_510'
SELECT RIGHT(@str,CHARINDEX('_',REVERSE(@str))-1)
Output:
510