Can you really write a where statement that utilizes the column title that's been designated towards the column as opposed to the column title that really is available? The whole table is produced dynamically using the column names saved in another table. I've got a function that enables customers to include filters for an jobect before locating the group of data that complements it.
Illustration of things i am trying:
SELECT id, col1 as [description], col2 as [date1], col3 as [image], col4 as [date2], col5 as [link], col6 as [location], col7 as [price], col8 as [title] FROM tableName WHERE [title] = 'Lemons'
Build your original query a subquery:
SELECT * FROM ( SELECT id, col1 as [description], col2 as [date1], col3 as [image], col4 as [date2], col5 as [link], col6 as [location], col7 as [price], col8 as [title] FROM tableName ) as subquery WHERE [title] = 'Lemons'
Keith's response is correct, however i will expound upon the why. You can't reference a column alias within the WHERE clause. The reason behind this really is based on an order the system processes the command. We see this command and browse in the top lower. However, the database engine examines it based as some claims. It reads your FROM statement first to find out which tables to gain access to. After that it reads your WHERE statement to determine what data to incorporateOrleave out. Finally it appears at the Choose statement to determine which data to exhibit.
Since the overall statement is examined within this order, the WHERE statement does not need the aliases produced within the Choose statement because individuals aliases haven't yet been processed. Therefore, it's not strictly easy to reference a column alias within the WHERE statement. The most popular method of getting for this would be to wrap the whole statement in the subquery. The only real problem with this particular is you will experience a performance hit. The reason behind this really is that you'll be coming back all rows after which getting rid of some rather than doing the elimination prior to the retrieval.