Column Alias browsing by tag


Using the field name alias in SQL Where clause

Tuesday, March 17th, 2009

Often I encounter SQL queries where I would love to use the alias names of my columns in the WHERE clause, today while trawling around the web I found a cool and easy way to do it. Here’s an example:

WITH Customer_Info AS
SELECT (Surname + ‘, ‘ + Firstname) AS FullName,
(Address_Line_1 + ‘,’ + Address_Line_2) AS Customer_Address
FROM Customers
SELECT FullName, Customer_Address
FROM Customer_Info
WHERE FullName LIKE ‘Smith%’

Written by Deepak Vasa - Visit Website