Reply to Re: Error message on using union statement with order by using reserved words

Your name:

Reply:


Posted by --CELKO-- on 10/31/07 14:07

>> I am trying to order the results of the UNIONs by the absolute value
in the column Difference. 'Difference' is a reserved word which is
why it appears in square brackets. <<

The Standard SQL convention is to use double quotes, not proprietary
brackets. Likewise, the Standard SQL convention is that columns in a
UNION result do not have names; you have to give them names in an AS
clause. Finally, the Standard SQL convention is that the ORDER BY
clause reference column names in the SELECT clause of the cursor, not
expressions.

SELECT X.book_name, X.external_id, X.d1mtm, X.poolmtm,
X.difference_abs, X.comments
FROM (#Revreps
UNION
SELECT book_name, external_id, d1mtm, poolmtm,
ABS("difference"), comments
FROM #RevrepDeals
) AS X (book_name, external_id, d1mtm, poolmtm, difference_abs,
comments)
ORDER BY external_id DESC, book_name ASC, difference_abs DESC;

A little minor effort and you have portable SQL instead of dialect!

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация