我是SQL新手并且正在使用Access 2013.我正在尝试构建一个CASE语句,该语句查看列中的值并为列中的每个记录分配一个类别编号。当我尝试运行我的代码时,我不断收到“遗失操作员”消息。我在下面列出了我的代码并感谢任何帮助。感谢
SELECT P.REGISTRATION_NUMBER, P.DATA_INDICATOR, D.TERRITORY_ID, P.PRODUCT_NAME, P.JAN_13_TRX, P.DEC_12_TRX, P.NOV_12_TRX, P.OCT_12_TRX, P.SEPT_12_TRX, P.AUG_12_TRX, P.JULY_12_TRX, P.JUNE_12_TRX, P.MAY_12_TRX, P.APR_12_TRX, P.MAR_12_TRX, P.FEB_12_TRX, (P.JAN_13_TRX+P.DEC_12_TRX+P.NOV_12_TRX+P.OCT_12_TRX+P.SEPT_12_TRX+P.AUG_12_TRX+P.JULY_12_TRX+P.JUNE_12_TRX+P.MAY_12_TRX+P.APR_12_TRX+P.MAR_12_TRX+P.FEB_12_TRX) AS ROLLING_12 INTO ESTROGEL_WITH_ROLLING_12
FROM Ascend_presc_data AS P INNER JOIN Ascend_demo AS D ON P.REGISTRATION_NUMBER = D.REGISTRATION_NUMBER
WHERE (((P.DATA_INDICATOR)=1) AND ((P.PRODUCT_NAME)='ESTROGEL'))
(CASE
WHEN P.ROLLING_12 > 199 THEN 10
WHEN P.ROLLING_12 > 99 THEN 9
WHEN P.ROLLING_12 > 49 THEN 8
WHEN P.ROLLING_12 > 19 THEN 7
WHEN P.ROLLING_12 > 9 THEN 6
WHEN P.ROLLING_12 > 4 THEN 5
WHEN P.ROLLING_12 = 4 THEN 4
WHEN P.ROLLING_12 = 3 THEN 3
WHEN P.ROLLING_12 = 2 THEN 2
WHEN P.ROLLING_12 = 1 THEN 1
ELSE 0
END) AS CATEGORY;
答案 0 :(得分:6)
CASE在MS Access中不可用,请查看Switch,IIF或更高版本,这是一个可以加入或比较的值的查找表。
切换:http://www.techonthenet.com/access/functions/advanced/switch.php
答案 1 :(得分:3)
SELECT
P.REGISTRATION_NUMBER,
...
FROM
Ascend_presc_data AS P
...
WHERE (((P.DATA_INDICATOR)=1) AND ((P.PRODUCT_NAME)='ESTROGEL'))
AND <<MISSING STATEMENT>> =
(SWITCH
P.ROLLING_12 > 199,10
P.ROLLING_12 > 99, 9
P.ROLLING_12 > 49, 8
P.ROLLING_12 > 19, 7
P.ROLLING_12 > 9, 6
P.ROLLING_12 > 4, 5
P.ROLLING_12 = 4, 4
P.ROLLING_12 = 3, 3
P.ROLLING_12 = 2, 2
P.ROLLING_12 = 1, 1
END));