Total PageViews

Tuesday, March 21, 2023

How to cut the string up to first slash “\” from the right-hand side in SQL Server

Suppose we have a string in which we are having slash “\” character in between and we have the condition to cut the string up to the first slash from the right-hand side then we can handle this scenario with the help of the below statements.

Declare @V_String Varchar(100)

Set @V_String='Hello User\How are you doing today'

 

Select @V_String

O/P: Hello User\How are you doing today

Now as per the condition to cut the string up to the first slash dynamically, then we can use the below logic to get the desired output.

Select (reverse(left(reverse(@V_String), charindex('\', reverse(@V_String)) - 1)))

O/P: How are you doing today

 

 

What other ideas can you add to this post that I may have not mentioned?