问题
(SELECT t.seccolumnname 'td'
FROM DbName.TableName t
WHERE t.firstcolumname = 1
ORDER BY t.seccolumnname)
FOR XML PATH('tr'), ROOT ('table')
It gives me an error : Incorrect syntax near the keyword 'order'.
Any ideas and suggestions
回答1:
Not sure why you have it in brackets? Try
SELECT t.seccolumnname 'td'
FROM DbName.TableName t
WHERE t.firstcolumnname = 1
ORDER BY t.seccolumnname
FOR XML PATH('tr'), ROOT ('table')
回答2:
I can say that ORDER BY clause is invalid in derived tables, as you write in the script above.
来源:https://stackoverflow.com/questions/8039085/sql-order-by-clause-in-for-xml