I have a string which looks like BAT | CAT | RAT | MAT I want to split this string into 4 parts and then store them into 4 different variables say .. @a,@b,@c,@
for splitting around a char :
DECLARE @A VARCHAR (100)= 'cat | bat | sat'
SELECT items
INTO #STRINGS
FROM dbo.split(@A,'|')
also see this link
DECLARE @test varchar(max);
set @test = 'Peter/Parker/Spiderman/Marvel';
set @test = Replace(@test, '/', '.');
SELECT ParseName(@test, 4) --returns Peter
SELECT ParseName(@test, 3) --returns Parker
SELECT ParseName(@test, 2) --returns Spiderman
SELECT ParseName(@test, 1) --returns Marvel
SQL Server 2005 : split string into array and get array(x)?
workarounds for splitting strings:
http://www.sqlperformance.com/2012/07/t-sql-queries/split-strings