Modifying T-SQL query to return XML results

Hello Forum,
I am very new to XML and having trouble modifying a query to return the results as XML. The XML element should be named "Person". The attribute LastName has a data type of (Name(Nvarchar(50))), not null) and belongs to a table called Person.Person. When I run the query below to try it I get an error stating Msg 207, Level 16, State 1, Line 29
Invalid column name 'Person'.

    SELECT TOP 1 LastName
    FROM AdventureWorks2014.Person.Person
    FOR XML AUTO

Thank you in advance for your help.
RM

Works for me. I executed your query against AdventureWorks2012 and got:

<AdventureWorks2012.Person.Person LastName="Abbas" />

as output.

I cannot see any reference to a column called Person in your query. The only column there is LastName

1 Like