Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Splitting CSV Values - SQL Server

RSS
Modified on Wed, Feb 16, 2022, 4:35 PM by Administrator Categorized as Uncategorized
create or alter function dbo.SplitCsv
(
	@IdsCsv varchar(max)
)
returns @result table 
(
	Id int not null
)
as
begin
	
declare
    @IdsXml xml = '<x v="' + replace(@IdsCsv, ',','"/><x v="') + '"/>'

insert into @result(Id)
select  
    n = T.c.value('@v', 'int')
from
    @IdsXml.nodes('x') T(c)	

return 

end

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.