I have database in XML, which I need export to SQL Server DB.
So, I can export xml such as: tag=”value”
But my XML is: <tag>value</tag>.
My query:
DECLARE @tempTable TABLE (
userId INT,
userName NVARCHAR(50),
password NVARCHAR(50)
)
DECLARE @xml XML
SET @xml="my_XML"
INSERT INTO @tempTable<br />
SELECT Tbl.Col.value('@userId', 'INT'),<br />
Tbl.Col.value('@userName', 'NVARCHAR(50)'),<br />
Tbl.Col.value('@password', 'NVARCHAR(50)')<br />
FROM @xml.nodes('//row') Tbl(Col)
SELECT * FROM @tempTable
Can I convert first case to second case?
Or maybe there are another way?
Sample of XML data:
<row>
<userId>1</userId>
<userName>Alpha</userName>
<password>1234</password>
</row>
<row>
<userId>2</userId>
<userName>Beta</userName>
<password>5678</password>
</row>
When I try to import it, I receive datatable with 2 rows with NULL cells.
So you want…?