Reputation: 5343
I wan t to upload the xml data to the sql table. I am passing the xml data from .net(c#)(Working fine)
code:
ALTER PROCEDURE [dbo].[BookDetails_Insert] (@xml xml)
AS
insert into BookDetails (Pages,Descriptions)
SELECT
ParamValues.PLName.value('.','int'),
ParamValues.PLDEscr.value('.','text')
FROM
@xml.nodes('/booksdetail/Pages') as ParamValues(PLName)
@xml.nodes('/booksdetail/Description') as ParamValues(PLName, PLDEscr)
xml Code:
<booksdetail>
<isbn_13>70100048</isbn_13>
<isbn_10>00048B</isbn_10>
<Image_URL>http://www.thenet.com/Book/large/00/701001048.jpg</Image_URL>
<title>QUICK AND FLUPKE</title>
<Description>QUICK AND FLUPKE </Description>
</booksdetail>
<booksdetail>...</booksdetail>
Problem: It is not doing anything on the table.
Upvotes: 0
Views: 640
Reputation: 63338
Your sample xml does not have a Pages
node. This means that when the FROM
clause is computed, a cross join is formed between a list of zero rows and a list of one row. The resulting product has no rows, so there is nothing SELECT
ed, so nothing is INSERT
ed.
If you actually want to insert one row into BookDetails
for each booksdetail
node in the incoming xml, you should do something like
SELECT
ParamValues.PL.value('Pages[1]','int'),
CAST(ParamValues.PLr.value('Description[1]','varchar(max)') AS text)
FROM
@xml.nodes('/booksdetail') as ParamValues(PL)
That is, shred the incoming xml into booksdetail
nodes, and pull out each of the .value
s you want from these rows.
Upvotes: 1