I have come across some code that says
select null as UnitCost,
null as MarkUp
What exactly is this doing? Is it getting the field names unitcost and markup?
Why would you use "select null as..."?
New to this sorry.
Thanks.
That code is aliasing the value null and calling it UnitCost/MarkUp. It is not selecting that column from any available table.
You would usually see this when a statement requires matching column sets, e.g. union all.
select id, col1, col2, null as UnitCost, null as MarkUp
from table_1
union all
select id, null as col1, null as col2, UnitCode, MarkUp
from table_2
Just populate NULL to those selected columns
It is useful when you do Insert...Select, the Table you are trying to insert may have more columns than the selected table has, for convenience, you could use select null as col_name to let the numbers of columns you are trying to insert matches the columns that the target table has.
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