I need to generate alias based on column names as shown in below query. Please suggest how to achieve this. I will be using it inside a stored procedure.
select N.ipAddress,
(case when sid = 185 and M.rid = 13785 then M.avg else 0 end) as {R.name + M.name},
(case when sid = 187 and M.rid = 13753 then M.avg else 0 end) as {R.name + M.name}
from statsTable as M,ipTable as N, resTable as R where M.rid in (13784,13751,13745,13746,13753,13748,13785) and M.sid in (185,187) and R.ipAddress = N.ipAddress and M.rid = R.rid and M.timestamp = 1463855400 group by N.ipAddress,M.sid