-1

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 部分に達していないためかもしれません。:-) 誰でも助けてください。エラーが見つかりません。

最高のPmelch

4

1 に答える 1

1

あなたの SQL ステートメントには少なくとも 2 つの問題があります。

CASEまず、Access SQL はキーワードをサポートしていません。T-SQLCASE ... WHEN (Microsoft SQL Server) のコンストラクトを考えていた場合、Access SQL で同等のものは関数です (参照:こちら)。関数は次のように考えることができますSwitch()Switch()

Switch(when1, then1, when2, then2, ...)

第二に、私が知る限り、Access SQL はピリオド ( .) を小数点記号として、カンマ ( ,) を区切り記号としてのみサポートします。これは、マシンの地域設定で他の値が指定されている場合でも (例:,小数点記号としてカンマ ( )、半記号としてカンマ ( )) -コロン ( ;) をリスト区切り文字として)。言い換えれば、私はかなり確信しています

left(KU.man_year_source;3)

うまくいきません。使用する必要があります

left(KU.man_year_source,3)

代わりは。

于 2013-11-15T13:22:33.643 に答える