12

我在 access 2007 中使用 switch 语句,我想知道如何指定默认值

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

谢谢

4

3 回答 3

24
SELECT
Switch(MyTable.[MyCol]='1','Terrestrial',
MyTable.[MyCol]='2','Value is two',MyTable.[MyCol]='3','Value is three',
True,'Error') AS ColumnName
FROM MyTable;
于 2013-04-30T06:49:23.287 回答
15
select 
  switch
  (
  MyCol = 1, 'Value is One',
  MyCol = 2, 'Value is Two'
  True,"Default"
  ) from MyT

参考:

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

于 2013-04-30T06:59:28.803 回答
0

Swich 命令的语法是:

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

请注意,DefaultResult是一个可选参数,如果实际数据与任何测试用例都不匹配,它将提供响应。

于 2018-04-19T07:43:13.303 回答