Use a named custom column in SQL 2005 in WHERE clause?
- by Orange Kid
Can I name a custom column in the SELECT statement and reference that in the WHERE clause without duplicating code?
For example;
SELECT RIGHT(REPLICATE('0', 5) + RTRIM(SOME_ID)), 5) AS DISPLAY_ID
FROM dbo.MY_TABLE
WHERE DISPLAY_ID LIKE '%005%'
Only much more complicated. I want to maintain this code in one place only but SQL Server 2005 forces me to duplicate the custom SELECT in the WHERE clause.
I believe this was possible in Microsoft SQL Server 2000 but no longer in 2005.
Thanks.