April 16, 2025 at 10:32 am
Hi all,
I want to separate string within a table column, accordint to a specific character.
eg.
Field Value: test1,test2,test3,test4
Expected Result (break by character ","):
New Field
test1
test2
test3
test4
Any help?
April 16, 2025 at 10:35 am
explanation: I don't know the number of delimiter characters in each row (in my example, the character "," may have different number of occurences in each row).
April 16, 2025 at 10:45 am
also, in each occurence of the character, I need a counter which will increase and show me for each record of the resultset which is the occurence sequense.
April 16, 2025 at 10:51 am
Take a look at the delimitedsplit functions, do these do what you need.
https://www.sqlservercentral.com/forums/topic/using-the-delimitedsplit8k-function-help-jeff
April 16, 2025 at 9:47 pm
DROP TABLE IF EXISTS #ToSplit;
CREATE TABLE #ToSplit
(
SplitCol VARCHAR(8000) NOT NULL
);
INSERT #ToSplit
(
SplitCol
)
VALUES
('test1,test2,test3,test4')
,('test5,test6');
SELECT ts.SplitCol
,ss.value
FROM #ToSplit ts
CROSS APPLY STRING_SPLIT(ts.SplitCol, ',') ss;
May 6, 2025 at 5:48 am
Use string split functions to separate by comma within the column.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy