FOR XML Syntax

  • Hi,

    I'm new to the forums. So Hello, hello.

    Quick question! Is this syntax valid?

    "FOR XML AUTO, RAW"

    I can't see that it is but I'm due to take my 70-461 exam in the future and I was going through some example exams and one of them said this was in the correct answer.

    Can anyone confirm for me, as when I try I get a syntax error.

    Many Thanks

    Darren

  • dlsilsbury 63952 (4/10/2015)


    Hi,

    I'm new to the forums. So Hello, hello.

    Quick question! Is this syntax valid?

    "FOR XML AUTO, RAW"

    I can't see that it is but I'm due to take my 70-461 exam in the future and I was going through some example exams and one of them said this was in the correct answer.

    Can anyone confirm for me, as when I try I get a syntax error.

    Many Thanks

    Darren

    Not valid, it's either auto, raw,path or explicit not a combination

    😎

    [ FOR { BROWSE | <XML> } ]

    <XML> ::=

    XML

    {

    { RAW [ ('ElementName') ] | AUTO }

    [

    <CommonDirectives>

    [ , { XMLDATA | XMLSCHEMA [ ('TargetNameSpaceURI') ]} ]

    [ , ELEMENTS [ XSINIL | ABSENT ]

    ]

    | EXPLICIT

    [

    <CommonDirectives>

    [ , XMLDATA ]

    ]

    | PATH [ ('ElementName') ]

    [

    <CommonDirectives>

    [ , ELEMENTS [ XSINIL | ABSENT ] ]

    ]

    }

    <CommonDirectives> ::=

    [ , BINARY BASE64 ]

    [ , TYPE ]

    [ , ROOT [ ('RootName') ] ]

  • Thanks for the reply. That puts my mind at rest.

    Believe it or not the source of the question was the latest testking virtual/practice test. I know they're frowned upon, but I thought I'd try it. Wish I hadn't as I've no confidence in it at all now.

    So be warned!!! 🙂

  • No, you cannot use them in combination, they must be used separately:

    USE [AdventureWorks2012]

    GO

    select TOP 50 [BusinessEntityID], [Title], [FirstName], [MiddleName], [LastName], [Suffix]

    from Person.Person

    FOR XML RAW

    select TOP 50 [BusinessEntityID], [Title], [FirstName], [MiddleName], [LastName], [Suffix]

    from Person.Person

    FOR XML AUTO

    select TOP 50 [BusinessEntityID], [Title], [FirstName], [MiddleName], [LastName], [Suffix]

    from Person.Person

    FOR XML PATH('Person'), ROOT('Person.Person')

    Check following link to know how to work with XML data with SQL queries: http://sqlwithmanoj.com/xml-sql/[/url]

    Check my blog post where I've Detailed about 70-461 exam and the stuff that you need to go through.

    Link: http://sqlwithmanoj.com/2012/11/16/passed-70-461-exam-querying-microsoft-sql-server-2012/[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply