我是SQL语言的新手,我正在尝试为Access中的Uni做一些工作。我有三列:Bindugen,其值如下所示,然后是空白列代码和33 / SDGL:
Bindungen:33,811,/ 811,SDGL,33,/ 33,812,SDGL,/ 812,SDGL,/ 811,(等等)
我的主要专栏是Bindungen,我希望填补其他与此相关的内容。基本上在33 / SDGL列中,我尝试执行下面显示的Update Case When Statement。它显然没有用。
SELECT
FROM Codes;
UPDATE (Codes)
SET 33/SDGL ( CASE
WHEN Bindungen = "*," THEN Allein
WHEN Bindungen = "33,*," Or "*,33," THEN 33
WHEN Bindungen = "SDGL,*," Or "*,SDGL," THEN SDGL
ELSE Both
END);
我对33 / SDGL专栏的目标是,当Bindungen是:" ," = Allein /" ,33,"或者" 33,," = 33 /" ,SDGL,"或者" SDGL,*," = SDGL
其余= BOTH
有人可以帮我写这个SQL代码吗?
同样对于Code列,我希望从Bindungen找到哪些代码(例如:811或812)。有人能指出我正确的方向吗?
答案 0 :(得分:0)
MS Access不使用CASE语句。您需要编写SWITCH语句,如下所示:
SWITCH(Bindungen = "*,", Allein, Bindungen = "33,*,", 33, Bindungen = "*,33,", 33,
Bindungen = "SDGL,*,", SDGL, Bindungen = "*,SDGL,", SDGL, BOTH)
另请注意,在这种情况下,Allein
,SDGL
和BOTH
必须是您要选择的字段。如果您只想要文本而不是字段值,请将这些单词包装在"双引号"。