0

I created an alias and checked whether alias column is null or not null but alias is not working in sql data warehouse.

select (emp_id)  a

from dbo.test b

where a is not null

Msg 207, Level 16, State 1, Line 1
Invalid column name 'a'.
  • Where emp_id is not null – John Cappelletti Oct 29 '18 at 22:04
  • @JohnCappelletti thanks for your response but why we need alias? –  Oct 29 '18 at 22:05
  • You don't NEED the alias A. You just can't reference the alias in the where – John Cappelletti Oct 29 '18 at 22:06
  • If I have a multiple columns and I need check whether its null or not then Do I need to write multiple condition after where statement? where emp_id is not null, emp_name is not nul,age is not null instead of select (emp_id,emp_name,emp_age) a from dbo.test b where a is not null –  Oct 29 '18 at 22:13

1 Answers1

0

You can't Use alias as simple as in where clause. But there are other ways which you can implement it

  • Using CTE
  • CROSS APPLY/OUTER APPLY

There are good examples at here for you to look-out

Jayendran
  • 9,638
  • 8
  • 60
  • 103