I am having an issue where I am working on table aliases and ran into a weird issue. I am able to use null as column name when I am not using table alias, but if I use a table alias I run into issues.
works!
select top 10 eid, null as emp_no from employee
does not work!!
select top 10 e.eid, null as e.emp_no from employee e
Is there a way out? I am running into an issue when I join with another table.
Trying to make it work !
select top 10 e.eid, null as e.emp_no, ed.desgination from employee e
inner join employee_designations ed on e.eid=ed.eid
Error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Try:
select top 10 e.eid, null as emp_no from employee e
You can alias NULL, but SQL will throw a hissy-fit if you claim that it's from table alias e.
UPDATE:
To use the NULL in a join, turn it into a subquery:
SELECT e.eid
, e.emp_no
FROM (
SELECT TOP 10 eid
, NULL AS emp_no
FROM employee
) AS e
Alias your subquery as e and now SQL will happily accept NULL as e.emp_no.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With