Converting XML to Table in SQL Server
Hello everyone. In this article, I will try to give information about converting XML to table in SQL Server.
In SQL Server you may want to convert XML to table in some cases.
You can easily do this by revising the sample code below.
DECLARE @TempTablo TABLE (
KullaniciId INT
,KullaniciAdi NVARCHAR(50)
,Sifre NVARCHAR(50)
)
DECLARE @xml XML
SET @xml = '
<row KullaniciId="1" KullaniciAdi="Yavuz" Sifre="1234" />
<row KullaniciId="2" KullaniciAdi="Selim" Sifre="5678" />'
INSERT INTO @TempTablo
SELECT
Tbl.Col.value('@KullaniciId', 'INT')
,Tbl.Col.value('@KullaniciAdi', 'NVARCHAR(50)')
,Tbl.Col.value('@Sifre', 'NVARCHAR(50)')
FROM @xml.nodes('//row') Tbl (Col)
SELECT
*
FROM @TempTablo
When you run the above code, you will see a result similar to the one below.
Good luck to everyone in business and life.