TSQL: Find Left and Right of String from a Delimiter

Example below shows how to split a string into left and right components based on a delimiter…

DECLARE @Str1 varchar(100), @Str2 varchar(100),@Delims nvarchar(max)
SET @Str1 = '$1000/hour'
SET @Delims =N' ,:/;-';

SELECT LEFT (@Str1,patindex(N'%['+@Delims+']%',@Str1+N',')-1) as LeftSide,
case when len(@Str1)-patindex(N'%['+@Delims+']%',@Str1+N',')>0 then
END AS RightSide

About AussieBICG

Connect with me here https://au.linkedin.com/in/aussiebicg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s