I understand that I can't reference an alias in the WHERE clause, but why is that? Is it interpreted differently?
Something like this generates an error:
declare @myTable table
(
num numeric(5,2),
den numeric(5,2)
)
insert into @mytable
select 1, 2
union
select 1, 3
union
select 2, 3
union
select 2, 4
union
select 2, 5
union
select null, 1
select num/den as 'calc' from @myTable
where calc is not null
order by calc
But this returns rows:
declare @myTable table
(
num numeric(5,2),
den numeric(5,2)
)
insert into @mytable
select 1, 2
union
select 1, 3
union
select 2, 3
union
select 2, 4
union
select 2, 5
union
select null, 1
select num/den as 'calc' from @myTable
--where calc is not null
order by calc