Reply to Re: Select statement query

Your name:

Reply:


Posted by Plamen Ratchev on 01/29/08 14:48

You cannot directly reference an aliased column in the same SELECT
statement, you would have to repeat the expression. However, you can use a
derived table (or a Common Table Expression if on SQL Server 2005 -
http://msdn2.microsoft.com/en-us/library/ms190766.aspx). Here is an example
using derived table:

SELECT elapsed_days,
CASE WHEN elapsed_days > 60
THEN 'Over 60 days'
ELSE 'Less than 60 days'
END AS msg
FROM (SELECT CASE
WHEN 1 = 1
THEN DATEDIFF(dd, '20080118', '20080120')
END
) AS T (elapsed_days)


HTH,

Plamen Ratchev
http://www.SQLStudio.com

[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

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