create the UFN_STRING_SPLIT
function suggested by @Dave here link
create FUNCTION [dbo].[UFN_STRING_SPLIT]
(
@List NVARCHAR(MAX),
@Delimiter NVARCHAR(255)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
(
SELECT Item = y.i.value('(./text())[1]', 'nvarchar(max)')
FROM
(
SELECT x = CONVERT(XML, '<i>'
+ REPLACE(@List, @Delimiter, '</i><i>')
+ '</i>').query('.')
) AS a
CROSS APPLY x.nodes('i') AS y(i)
);
test your code:
select
Left(Item, charindex('=', Item, 0) - 1) as FielName,
right(Item, len(Item) - charindex('=', Item, 0)) as [Value]
from
dbo.UFN_STRING_SPLIT('ReferenceId=678&MobileNo=226789&Pnumber=9878&SIB=121314', '&')
2
solved Separate a value from string in SQL Server 2012 [duplicate]