I'm having some trouble parsing some data that I get that is in the following format:
1. FREE_AGENT "10710,|9452,"
2. FREE_AGENT "11381,|2918,"
3. FREE_AGENT "10220,|"
4. FREE_AGENT "9625,|"
5. FREE_AGENT "11213,11225,11193,|"
everything before the ,|
delimiter is considered a player add, everything after the ,|
delimiter is considered a drop.
Ideally I'd like to get this parsed out into rows such as the following:
1. FREE_AGENT ADD "10710"
1. FREE_AGENT DROP "9452"
2. FREE_AGENT ADD "11381"
2. FREE_AGENT DROP "2918"
3. FREE_AGENT ADD "10220"
4. FREE_AGENT ADD "9625"
5. FREE_AGENT ADD "11213"
5. FREE_AGENT ADD "11225"
5. FREE_AGENT ADD "11193"
any help would be appreciated. I have basic t-sql string splitters but not getting much luck such as
CREATE FUNCTION split(
@delimited NVARCHAR(MAX),
@delimiter NVARCHAR(100)
) RETURNS @t TABLE (id INT IDENTITY(1,1), val NVARCHAR(MAX))
AS
BEGIN
DECLARE @xml XML
SET @xml = N'<t>' + REPLACE(@delimited,@delimiter,'</t><t>') + '</t>'
INSERT INTO @t(val)
SELECT r.value('.','varchar(MAX)') as item
FROM @xml.nodes('/t') as records(r)
RETURN
END