[AccessD] A use for Switch()

Gustav Brock gustav at cactus.dk
Fri Oct 10 08:28:17 CDT 2003


Hi all

I've never found a use for Switch() but the other day a client asked
me to sort a small combobox in a weird way without adding a new column
with a sort index.

Here you can use Switch().
An example is how to sort colours by description:

<SQL>

  SELECT
    ID,
    Description
  FROM
    tblColours
  ORDER BY
    Switch(
      [Description]="Red",1,
      [Description]="Yellow",2,
      [Description]="Green",3,
      [Description]="Cyan",4,
      [Description]="Blue",5,
      [Description]="Magenta",6,
      True,9);

</SQL>

Note the last item for "catch any not listed".

/gustav



More information about the AccessD mailing list