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

Ex:

Advertisement

From → SQL

Leave a Comment

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 )

Connecting to %s

%d bloggers like this: