0

我正在尝试更新文本字段。将数据移动到另一列并截断,因为它太长了。

更新语句如下所示。(已编辑)

UPDATE Feuil1 SET [Occupant 2] = SWITCH
(
[Occupant 2] IS NOT NULL, [Occupant 3],
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 3), mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 4), mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 5), mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 6), mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 7), mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
     (LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 2), '',
     (LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 1), '',
     [Occupant 1] LIKE '* & *', mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
     [Occupant 1] LIKE '* ET *', mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," "),30),
     (LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 0), ''
), [Occupant 1] = SWITCH
(
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 3), mid([Occupant 1],1,InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," ")),
(LEN([Occupant 1]) - LEN(REPLACE([Occupant 1], ' ', '')) = 4), mid([Occupant 1],1,InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," ")),
[Occupant 1] LIKE '* & *', (replace([Occupant 1], ' & ' & mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," ")),InStr(InStr(2,[Occupant 1]," ")), '')),
[Occupant 1] LIKE '* ET *', (replace([Occupant 1], ' & ' & mid([Occupant 1],InStr(InStr(1,[Occupant 1]," ")+1,[Occupant 1]," ")),InStr(InStr(2,[Occupant 1]," ")), ''))
)
WHERE [Occupant 1] IS NOT NULL

我总是收到转换类型错误,但我不知道为什么。我正在使用自己修改的数据更新文本字段。所有涉及的列都是文本。

我尝试使用 Val()、Cstr() 函数,结果相同。

附加信息:似乎处理了一些数据,但我找不到原因。

有什么线索吗?

4

1 回答 1

2

在您的声明的开头,您有以下几行:

UPDATE Feuil1 SET [Occupant 2] = SWITCH
(
[Occupant 2] IS NOT NULL, [Occupant 3] = [Occupant 2],

您在这里所说的是,如果 [Occupant 2] IS NOT NULL 则将 [Occupant 2] 设置为等于 [Occupant 3] = [Occupant 2] 的布尔结果(即,TrueFalse)。我猜您想将其更改为:

UPDATE Feuil1 SET [Occupant 2] = SWITCH
(
[Occupant 2] IS NOT NULL, [Occupant 3],

或者,更有可能:

UPDATE Feuil1 SET [Occupant 2] = SWITCH
(
[Occupant 2] IS NOT NULL, [Occupant 2],
于 2013-01-24T16:03:09.317 回答