SandPiper SandPiper - 11 months ago 42
SQL Question

Using SWITCH() With an Aliased Column Name

I am using MS-Access to display an aliased column, and I am trying to combine that with a SWITCH statement. The following code works:

SELECT column1 & column2 AS mycol FROM tablename

What I would like to do is the following pseudocode:

SELECT SWITCH(column1 & column2 AS mycol, mycol is null, 'NONE') FROM tablename

Basically, there is data in both columns or there is a null in both columns. If it is null, I want it to say "NONE", otherwise concatenate the two together. How do I change the syntax to make this work?

Answer Source

you shou assimg the alias at the result of switch

SELECT SWITCH( (column1 & column2)  is  null, 'NONE') AS mycol, FROM tablename