[英]MS Access VBA SQL query debugging select case
在MS Access 2013 VBA中,我在此SQL字符串中收到语法错误:
strSQL = "INSERT INTO [man_year] ( man_year_val, year_int, main_research_area, organisation, man_year_source ) SELECT KU.[2007], '2007' AS Expr1, " _
& "select case right(left(KU.man_year_source;6);2) like 'Hu' 3 case right(left(KU.man_year_source;6);2) like 'Sa' 1 case right(left(KU.man_year_source;6);2) like 'Te' 2 case right(left(KU.man_year_source;6);2) like 'Su' 4 case right(left(KU.man_year_source;6);2) like 'Ud' 5 AS Expr2, " _
& "4 AS Expr3, " _
& "select switch" _
& "(left(KU.man_year_source;3) like '1. '; 1;" _
& "left(KU.man_year_source;3) like '1.1'; 4;" _
& "left(KU.man_year_source;3) like '1.2'; 5;" _
& "left(KU.man_year_source;3) like '1.3'; 6;" _
& "left(KU.man_year_source;3) like '1.4'; 7;" _
& "left(KU.man_year_source;3) like '1.5'; 8;" _
& "left(KU.man_year_source;3) like '1.6'; 9;" _
& "left(KU.man_year_source;3) like '2. '; 2;" _
& "left(KU.man_year_source;3) like '2.1'; 47;" _
& "left(KU.man_year_source;3) like '2.2'; 48;" _
& "left(KU.man_year_source;3) like '2.3'; 49;" _
& "left(KU.man_year_source;3) like '2.4'; 50;" _
& "left(KU.man_year_source;3) like '2.5'; 51;" _
& "left(KU.man_year_source;3) like '2.6'; 52;" _
& "left(KU.man_year_source;3) like '3. '; 3;" _
& "left(KU.man_year_source;3) like '3.1'; 53;" _
& "left(KU.man_year_source;3) like '3.2'; 54;" _
& "left(KU.man_year_source;3) like '3.3'; 55;" _
& "left(KU.man_year_source;3) like '3.4'; 56;" _
& "left(KU.man_year_source;3) like '3.5'; 57;" _
& "left(KU.man_year_source;3) like '3.6'; 58) from KU;"
我在CASE部分中得到了错误,但这可能是因为它尚未到达SWITCH部分。 :-)谁能帮忙,我找不到错误。
最佳产品
我发现您的SQL语句至少有两个问题:
首先,Access SQL不支持CASE
关键字。 如果您想到的是CASE ... WHEN
在T-SQL (Microsoft SQL Server)中的构造,则Access SQL中的等效项是Switch()
函数(参考: here )。 您可以将Switch()
函数视为
Switch(when1, then1, when2, then2, ...)
其次,据我所知,即使计算机上的“区域设置”指定了其他值(例如,逗号( ,
)作为小数点),Access SQL仅支持以句点( .
)作为小数点符号和逗号( ,
)作为列表分隔符。符号和分号( ;
)作为列表分隔符)。 换句话说,我相当确定
left(KU.man_year_source;3)
永远不会工作; 您需要使用
left(KU.man_year_source,3)
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.