是否可以在SQL中的CASE语句中包含多个Select语句

时间:2012-06-27 14:27:33

标签: sql-server-2008 foxpro

我正在尝试将Foxpro DB迁移到SQL Server ..我在Foxpro中有一个CASE语句,其工作原理如下..

CASE *variable* = 1 
    SELECT * FROM TABLEA INTO CURSOR A
CASE *variable* = 2
    SELECT * FROM TABLEB INTO CURSOR B
CASE *variable* = 3
    SELECT * FROM TABLEC INTO CURSOR C

CASE *variable* = N
    SELECT * FROM TABLEN INTO CURSOR N

有没有办法在不使用IF的情况下将此CASE语句转换为SQL?我假设在SQL Server CASE中只能在SELECT中编写。

谢谢..

1 个答案:

答案 0 :(得分:0)

这就是你要问的问题:

SELECT * FROM IIF(var = 1, 'table1', IIF(var = 2, 'table2', 'table3')) INTO CURSOR IIF(var = 1, 'cur1', IIF(var = 2, 'cur2', 'cur3'))