I seem to be having some trouble grasping the concept of using AS to create an alias, and then using that alias later. Here is an example of a very simple query that I get an error when I run:
SELECT IP,
(SELECT server_ip as IP
FROM table1
WHERE start_time BETWEEN @startdate AND @enddate
Group By server_ip)X
Group By IP
I would expect this to just return the results from the second select statement in the server_ip column. However I get an error messages saying IP is not an invalid column name. Can someone explain to me how to do this properly?