VBA SQL case when
时间: 2023-08-13 19:11:02 浏览: 260
sql 中 case when 语法使用方法
在VBA中,可以使用SELECT CASE语句来实现类似SQL中的CASE WHEN语句。例如,你可以使用以下代码来实现简单的CASE函数:
```
Dim sex As String
Dim result As String
sex = "1"
Select Case sex
Case "1"
result = "男"
Case "2"
result = "女"
Case Else
result = "其他"
End Select
```
在这个例子中,根据变量sex的值,选择不同的分支进行处理。如果sex的值是"1",则result的值将是"男";如果sex的值是"2",则result的值将是"女";否则,result的值将是"其他"。这样,你可以根据不同的条件执行不同的操作。\[2\]
#### 引用[.reference_title]
- *1* [Oracle SQL:重复使用CASE WHEN的子查询,而不必重复子查询](https://blog.csdn.net/weixin_39974811/article/details/113030144)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [[Excel VBA]用字典处理多条件查询问题](https://blog.csdn.net/weixin_30631587/article/details/98896929)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [SQL之CASE WHEN用法详解](https://blog.csdn.net/weixin_44688973/article/details/118808601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文