Skip to content

Instantly share code, notes, and snippets.

@RickyLin
Created February 24, 2021 02:04
Show Gist options
  • Save RickyLin/8c2e31595356d6bd7c59aba7043e6abd to your computer and use it in GitHub Desktop.
Save RickyLin/8c2e31595356d6bd7c59aba7043e6abd to your computer and use it in GitHub Desktop.
Extract values from XML type in SQL Server
DECLARE @Data XML
SET @Data = '<Ids>
    <Id>64122</Id>
    <Id>12345</Id>
    <Id>67890</Id>
</Ids>'
SELECT Ids.Id.value('text()[1]', 'varchar(100)')
FROM @Data.nodes('Ids/Id') AS Ids(Id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment