12

I am using switch statement in access 2007, i want to know how I can specify default value

select 
  switch
  (
  MyCol = 1, 'Value is One',
  MyCol = 2, 'Value is Two'
  ) from MyTable

Thanks

ApplePie
  • 8,814
  • 5
  • 39
  • 60
Mandeep Singh
  • 2,016
  • 7
  • 19
  • 32

3 Answers3

25
SELECT
Switch(MyTable.[MyCol]='1','Terrestrial',
MyTable.[MyCol]='2','Value is two',MyTable.[MyCol]='3','Value is three',
True,'Error') AS ColumnName
FROM MyTable;
Vikram Jain
  • 5,498
  • 1
  • 19
  • 31
14
select 
  switch
  (
  MyCol = 1, 'Value is One',
  MyCol = 2, 'Value is Two'
  True,"Default"
  ) from MyT

Refer:

http://www.utteraccess.com/forum/Switch-statement-default-t453140.html

Freelancer
  • 9,008
  • 7
  • 42
  • 81
0

The syntax for the Swich command is:

Switch(TestCase1, Result1, TestCase2, Result2, {As many more TestCases and Results as you need...}, DefaultResult)

Note that the DefaultResult is an optional parameter and will provide a response in the event that the actual data does not match any of the Test Cases.

Sunny Chawla
  • 361
  • 3
  • 4