DotNetUser
DotNetUser

Reputation: 239

sql ORDER BY clause IN FOR XML

(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

Upvotes: 2

Views: 9761

Answers (2)

DanezuBro
DanezuBro

Reputation: 1

I can say that ORDER BY clause is invalid in derived tables, as you write in the script above.

Upvotes: 0

Martin Smith
Martin Smith

Reputation: 452988

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')  

Upvotes: 4

Related Questions