Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Creating xml from SQL query

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 284
    Comment on it

    This blog will show you how to create an xml from sql query having sql data. Write down the followng query to generate xml:-

    WITH XMLNAMESPACES ('' as phr)
    Select OrderResultID,OrderID ,PatientID ,SpecimenNumber ,AccountNumber ,AccountPhoneNumber 
    ,PatientLastName ,PatientFirstName ,PatientMiddleInitial ,PatientSSN ,PatientPhone 
    ,PatientDOB ,PatientAgeYMD ,PatientSex from OrderResults
    where PatientID = 123456
    FOR XML RAW ('phr:Encounter'), ELEMENTS

    This will generate an xml like following:-

    <phr:Encounter xmlns:phr="">
    <PatientFirstName>Michelle </PatientFirstName>

    we just need to write the namespace which will be used in xml like:-

    WITH XMLNAMESPACES ('' as phr)

    and at the end of query need to give FOR XML RAW ('phr:Encounter'), ELEMENTS for creating xml.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: