Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver,microsoft.public.sqlserver.programming Subject: Re: Puzzling ORDER BY Followup-To: comp.databases.ms-sqlserver Date: Fri, 22 Jun 2012 11:31:08 +0200 Organization: Erland Sommarskog Lines: 21 Message-ID: References: <4fe3713b$0$6908$e4fe514c@news2.news.xs4all.nl> <4fe40fa8$0$6962$e4fe514c@news2.news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="nBFDv6s1VJQDuF1w6hpX2A"; logging-data="7099"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mpzPQPT+2OJpxx23kkYFY" User-Agent: Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) Cancel-Lock: sha1:4O6Et44yLXmxVYriRoc7FuczjBo= Xref: csiph.com comp.databases.ms-sqlserver:1149 Jeroen Mostert (jmostert@xs4all.nl) writes: > Yes, you're right -- if you supply a constant expression explicitly, SQL > Server will catch this and flag it as nonsensical. A bit overzealous, I > think. It's mostly harmless, compared to other things that aren't > detected. > > If you use "NULL + [column]", or any other expression that always yields > NULL but isn't constant, the error goes away. The CASE, of course, is > not a constant expression. Or you can say ORDER BY (SELECT NULL). Which is not very useful in the main ORDER BY for a query, but this is useful with row_number() when you don't care about the order. (ORDER BY is mandatory for row_number.) -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx