Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
DECLARE @underwriter NVARCHAR(MAX) = 'a:2:{i:0;s:4:"1985";i:1;s:4:"2001";}'; -- Reformat to valid XML and extract values WITH Split AS ( SELECT CAST( '<root><i>' + REPLACE( REPLACE( REPLACE( @underwriter, '";i:', '</i><i>' ), 'a:1:{i:0;s:4:"', '' ), 'a:2:{i:0;s:4:"', '' ) + '</i></root>' AS XML ) AS xml_data ) SELECT TRY_CAST(n.value('.', 'NVARCHAR(50)') AS INT) AS underwriter_ID FROM Split CROSS APPLY xml_data.nodes('/root/i') AS t(n) WHERE TRY_CAST(n.value('.', 'NVARCHAR(50)') AS INT) IS NOT NULL;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear