Posts

Showing posts from April, 2020

Splitting comma separated values into row values in SQL

Today we are going to see how to separate the comma separated values in sql. We are often come across these kind of situation to split strings with comma. So i hope this would be more helpful. --Declaration                                                                                  DECLARE @xml XML,@commaValues NVARCHAR(2000)         --Initialization SET @xml = N'<t>' + REPLACE(@commaValues ,',','</t><t>') + '</t>'    --Temporary table creation      CREATE TABLE #tmp(studentid int)        --Inserting values  in temporary table INSERT INTO #tmp          SELECT r.value('.','Nvarchar(MAX)') as item          FROM @xml.node...