How to pass XML from C# to a stored procedure in SQL Server 2008?

后端 未结 4 924
春和景丽
春和景丽 2020-11-30 06:55

I want to pass xml document to sql server stored procedure such as this:

CREATE PROCEDURE BookDetails_Insert (@xml xml)

I want compare some

4条回答
  •  春和景丽
    2020-11-30 07:04

    For part 2 of your question, see my answer to Stored procedure: pass XML as an argument and INSERT (key/value pairs) for an example of how to use XML within a stored procedure.

    EDIT: Sample code below is based on the specific example given in the comments.

    declare @MyXML xml
    
    set @MyXML = ' 
                      700001048 
                      01048B 
                      http://www.landt.com/Books/large/00/70100048.jpg 
                      QUICK AND FLUPKE 
                       PRANKS AND JOKES QUICK AND FLUPKE - CATASTROPHE QUICK AND FLUPKE  
                  '
    
    select Book.detail.value('(isbn_13/text())[1]','varchar(100)') as isbn_13, 
           Book.detail.value('(isbn_10/text())[1]','varchar(100)') as isbn_10, 
           Book.detail.value('(Image_URL/text())[1]','varchar(100)') as Image_URL, 
           Book.detail.value('(title/text())[1]','varchar(100)') as title, 
           Book.detail.value('(Description/text())[1]','varchar(100)') as Description
        from @MyXML.nodes('/booksdetail') as Book(detail)     
    

提交回复
热议问题