Use a named custom column in SQL 2005 in WHERE clause?

Posted by Orange Kid on Stack Overflow See other posts from Stack Overflow or by Orange Kid
Published on 2010-04-01T17:48:55Z Indexed on 2010/04/01 17:53 UTC
Read the original article Hit count: 184

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005