Skip to content

Split the string /Split the column value

December 20, 2022

a. The following statement splits the ColumnA value into rows and saves values into SplitValue column

Select pd.[ColumnA], TRIM(value) as SplitValue from Person_Detail pd CROSS APPLY string_split(pd.[ColumnA], ‘,’)

EX: If ColumnA value is C+AI, Azure CXP, EMEA then the above statement gives the following results.

b. The following statement splits ColumnA value and saves the substring after FIRST comma (“,”) into SplitValue column if ColumnA contains comma (‘,’) otherwise it saves the string into SplitValue

Select pd.[ColumnA], TRIM(SUBSTRING(pd.[ColumnA],charindex(‘,’,pd.[ColumnA])+1,len(pd.[ColumnA]))) as SplitValue from Person_Detail pd



From → SQL

Leave a Comment

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: