FOR XML PATH
FOR XML PATH is a SQL statement in the SQL Server Specific category. SQL Server: converts query results to XML format. Commonly used for string concatenation hack. The syntax is SELECT ... FOR XML PATH('element_name');. It returns xML result. A typical example: SELECT employee_name AS name, salary FROM employees FOR XML PATH('employee'), ROOT('employees'); -- <employees> -- <employee><name>Alice</name><salary>75000</salary></employee> -- <employee><name>Bob</name><salary>65000</salary></employee> -- </employees> -- CSV hack: SELECT STUFF((SELECT ', ' + name FROM employees FOR XML PATH('')), 1, 2, ''); A close relative is OUTPUT Clause, which sQL Server: returns values from DML statements (like PostgreSQL RETURNING). A close relative is STUFF(), which sQL Server: deletes a specified length of characters from a string and inserts another string at the start position. A close relative is TRY...CATCH, which sQL Server: structured error handling. Captures runtime errors in the CATCH block. More about this category: SQL Server-specific features — T-SQL, OUTPUT, TOP, PIVOT, STUFF, FOR XML.