我正在尝试将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中编写。
谢谢..
答案 0 :(得分:0)
这就是你要问的问题:
SELECT * FROM IIF(var = 1, 'table1', IIF(var = 2, 'table2', 'table3')) INTO CURSOR IIF(var = 1, 'cur1', IIF(var = 2, 'cur2', 'cur3'))