Example of using SQL Sp_xml_preparedocument function

Source: Internet
Author: User

Table structure:

CREATE FUNCTIONF_splitstr (@s   varchar(8000),--string to be split@split varchar(Ten)--Data Separators)RETURNS @re TABLE(colvarchar( -)) asBEGIN --Create a secondary table for split processing (only table variables can be manipulated in a user-defined function) DECLARE @t TABLE(IDint IDENTITYBbit) INSERT @t(b)SELECT TOP 8000 0  fromsyscolumns a,syscolumns bINSERT @re SELECT SUBSTRING(@sIdCHARINDEX(@split,@s+@split, ID)-ID) from @t WHEREId<=LEN(@s+'a')    and CHARINDEX(@split,@split+@s, ID)=IDRETURNENDGO
View Code
Create procTest asBegin    Declare @dataXMLDeclare @idoc int    Set @data=    (        SelectIpduid as '@pduid', Sconfig.query ('/items/item') fromXxx_baseinfowhereSconfig is  not NULL          forXML Path,root ('Configinfo')     )    --Create an internal representation of the XML document.    execsp_xml_preparedocument@idocOutput@data    --execute a SELECT statement that uses the OPENXML rowset provider.    Create Table#Tmp (Pduidvarchar( -), Prodlinevarchar( -), profamilyvarchar( -), PROPDTvarchar( -), Prodnovarchar( -)    )Insert  into#TmpSelect *  from (            SelectPduid, (SelectCol fromDBO.F_SPLITSTR (CustomerID,'/')WhereId=1) asProdline, (SelectCol fromDBO.F_SPLITSTR (CustomerID,'/')WhereId=2) asprodfamily, (SelectCol fromDBO.F_SPLITSTR (CustomerID,'/')WhereId=3) asPRODPDT, (SelectCol fromDBO.F_SPLITSTR (CustomerID,'/')WhereId=4) asProdno fromOPENXML (@idoc,'/configinfo/row/item',2)     with(Pduidvarchar( -)'.. /@pduid', CustomerIDvarchar( -)'@id'             )    )  asTexecSp_xml_removedocument@idocSelect *  from#TmpEnd
View Code

Example of using SQL Sp_xml_preparedocument function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.