Hi, How to use the alias column name ID the WHERE clause SELECT RoomType.RoomID AS ID, RoomType.PropertyID, RoomType.RoomName, RoomType.RoomDescription FROM RoomType WHERE ID = 116 I am getting this error Msg 207, Level 16, State 1, Line 1 Invalid column name 'ID'.
You cant use alias name directly in the WHERE clause You need to use the original column name/ expression WHERE Roomtype.RoomID=116
and if you use complex expression and want to use it in where clause, use derived table Select * from ( Your uery ) as t where alias_name=some_value
SELECT * FROM (SELECT RoomType.RoomID AS ID, RoomType.PropertyID, RoomType.RoomName, RoomType.RoomDescription FROM RoomType) X WHERE ID = 116 rOHIT