Ok, I have this code for the stored procedure right now.
ALTER PROC [dbo].[Readxml]
@xmlparam XML
AS
BEGIN
SET NOCOUNT ON
DECLARE @CustomerXml AS XML
SET @CustomerXml = @xmlparam
INSERT INTO Custtable.dbo.SPCustomer
(
CustomerId,
CustomerName
)
SELECT
Customer.attribute.value('CustomerId[1]', 'nvarchar(255)') AS CustomerId,
Customer.attribute.value('Name[1]', 'nvarchar(255)') AS CustomerName
FROM
@xmlparam.nodes('Customers/Customer') AS Customer(attribute)
END
My XML looks like this (simplified).
<Customers>
<Customer CustomerId="94" Name="name1" />
<Customer CustomerId="95" Name="name2" />
<Customer CustomerId="96" Name="name3" />
</Customers>
With my code right now I am not able to get the attribute values, as I understand I am trying to get elements inside the <Customer> tag, called CustomerId and Name, that don’t exist.
When selecting all rows from the table, after the procedure is done, I get all the rows but with NULL values.
My question, how do I get the attributes from the XML?
Thanks in advance!
You need this:
To get the attribute, use a leading
@