Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - contains an invalid XML identifier as required by FOR XML;

I'm running this query and getting below mentioned error. Can anyone help?

Column name 'Middle Name' contains an invalid XML identifier as required by FOR XML; ' '(0x0020) is the first character at fault.

SELECT 
    Username as [LastName],
    '' AS [Middle Name],
    '' AS Birthdate,
    '' AS [SSN],
    0 AS [Wage Amount]
    FROM
    Employee
     FOR XML PATH
like image 518
Conrad Jagger Avatar asked Jun 09 '16 16:06

Conrad Jagger


1 Answers

You can't have spaces in XML element or attribute names. Use

SELECT Username AS [LastName],
       ''       AS [MiddleName],
       ''       AS Birthdate,
       ''       AS [SSN],
       0        AS [WageAmount]
FROM   Employee
FOR XML PATH 
like image 141
Martin Smith Avatar answered Sep 19 '22 20:09

Martin Smith