如何在 MS Access 的追加查询中将数据类型从文本转换为 Yes/No?
How to convert data type from Text to Yes/No inside an append query in MS Access?
在 MS Access 中,我试图将数据从一个 table (Table A) 附加到另一个 table (Table B)。 Table A 有一个 'Short Text' 类型的列,只有一个值 'Even' 或 empty/null。 Table B 具有 Yes/No 类型的等效列。在进行此转换时,我必须将数据从 Table A 插入到 Table B - 如果 Table A 的列 'Even' 将 Table B 的值设置为 True ,否则,将其设置为 False。
我试过如下查询,但没有成功:
INSERT INTO TableB( BookName, ChapterName, PageNo, Even)
SELECT name, chapter, page, IIf(UCase([Even or Odd]) = 'EVEN', True,False)
FROM TableA;
以上查询给出了以下错误:
Microsoft Access can't append all the records in the append query.
Microsoft Access set 0 field(s) to Null due to a type conversion failure, and it didn't add 117 record(s) to the table due to key violations....
如何让 access 在附加数据时更改值?
正如您的错误屏幕所说,问题不在于转换数据类型,错误是由于密钥冲突。
尝试在没有此 yes/no 字段的情况下插入,您将确保这一点。
您可能在表之间存在关系,因此不允许插入某些值。
为了将来的搜索,这是我的最终查询:
INSERT INTO TableB( BookName, ChapterName, PageNo, Even)
SELECT name, chapter, page, IIf(UCase([Even or Odd])="EVEN",-1,0) AS EvenOdd FROM TableA;
要检查的内容,如果源和目标之间存在数据类型差异 table。就我而言,源 table 中的页面列为 number
,目标中的页面列为 Short Text
。
此外,不属于查询的主键是 Number
而不是 AutoNumber
,这是失败的,因此我得到了错误。
在 MS Access 中,我试图将数据从一个 table (Table A) 附加到另一个 table (Table B)。 Table A 有一个 'Short Text' 类型的列,只有一个值 'Even' 或 empty/null。 Table B 具有 Yes/No 类型的等效列。在进行此转换时,我必须将数据从 Table A 插入到 Table B - 如果 Table A 的列 'Even' 将 Table B 的值设置为 True ,否则,将其设置为 False。
我试过如下查询,但没有成功:
INSERT INTO TableB( BookName, ChapterName, PageNo, Even)
SELECT name, chapter, page, IIf(UCase([Even or Odd]) = 'EVEN', True,False)
FROM TableA;
以上查询给出了以下错误:
Microsoft Access can't append all the records in the append query. Microsoft Access set 0 field(s) to Null due to a type conversion failure, and it didn't add 117 record(s) to the table due to key violations....
如何让 access 在附加数据时更改值?
正如您的错误屏幕所说,问题不在于转换数据类型,错误是由于密钥冲突。 尝试在没有此 yes/no 字段的情况下插入,您将确保这一点。 您可能在表之间存在关系,因此不允许插入某些值。
为了将来的搜索,这是我的最终查询:
INSERT INTO TableB( BookName, ChapterName, PageNo, Even)
SELECT name, chapter, page, IIf(UCase([Even or Odd])="EVEN",-1,0) AS EvenOdd FROM TableA;
要检查的内容,如果源和目标之间存在数据类型差异 table。就我而言,源 table 中的页面列为 number
,目标中的页面列为 Short Text
。
此外,不属于查询的主键是 Number
而不是 AutoNumber
,这是失败的,因此我得到了错误。