split string by comma in sql server

CREATE FUNCTION Split
(
  @delimited nvarchar(max),
  @delimiter nvarchar(100)
) RETURNS @t TABLE
(
-- Id column can be commented out, not required for sql splitting string
  id int identity(1,1), -- I use this column for numbering splitted parts
  val nvarchar(max)
)
AS
BEGIN
  declare @xml xml
  set @xml = N'<root><r>' + replace(@delimited,@delimiter,'</r><r>') + '</r></root>'

  insert into @t(val)
  select
    r.value('.','varchar(max)') as item
  from @xml.nodes('//root/r') as records(r)

  RETURN
END
GO

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to split comma delimited string into rows sql split comma sql server split comma separated values in sql server 2012 sql server split a string into a comma separated string comma seperted value split in sql split comma separated string in rows sql how to split string by comma in sql server sql server in comma seprated string condicion in varchar split comma sql varchar split comma sql split comma separated string in sql sql split comma separated values sql string split with comma sql function split comma separated values separate string by comma sql server separate string with comma sql sql server 2008 separate string with comma sql split separator comma sql server how to split comma seperated string into rows in microsoft sql server how to split comma seperated string into rows in sql server split comma string sql split string comma separated sql server split comma separated values in sql server how to use comma split function in sql where clause how to call comma split function in sql where clause how to split comma separated string values in sql query example how to split comma separated values in sql query example how to call split comma string in sql split comma string in sql how to split string with comma in sql server exam example how to split comma in sql server split comma separated string in sql into rows sql server split string comma separated split text by comma to array in sql split text by comma in sql sql split string by comma how to split comma separated values check in sql query split string from comma in sql sql server separate string by comma split column with comma delimiter in sql server sql query to split string by comma and count sql query to split string by comma sql split by comma split comma separated string from table in sql sql split comma separated string t sql split string by comma how to split a string by comma and store values in sql split Comma in sql how to split comma separated values in sql query sql split string into columns by comma split by comma in sql server sql server split string by comma and loop split comma separated values in sql sql server 2008 split string by comma sql server split string by comma split string by comma sql server 2012 HOW to split comma seperated values in sql sql split comma delimited string into rows sql split string on comma split comma separated string in sql server 2012 comma separator in sql split Convert comma separated string into separate lines sql server sql split on comma h2 split string in sql server stored procedure sql split string by delimiter mysql split comma separated string into rows split string by comma sql split string function to split delimiter in t-sql split string by comma in sql select in COMA stored procedure sql server
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source