0

When I run the following query:

INSERT INTO outRawTbl
SELECT *
FROM (select * from [out|noRFI_BS_noRT]
union all
select * from [out|noRFI_BS_RT])  AS [%$##@_Alias];

I get this error:

Microsoft Access set 3854 field(s) to Null due to a type conversion failure

When I run the query as:

INSERT INTO outRawTbl
SELECT *
FROM (select * from [out|noRFI_BS_noRT]
union
select * from [out|noRFI_BS_RT])  AS [%$##@_Alias];

then I don't get this type conversion error, and all the data inserts successfully. I need to use UNION ALL because some of the fields in the queries are Memo fields and they'll be truncated to 255 chars if I use UNION.

I guess I can start trying to insert fields one at a time from the queries, but there are around 50 fields in each query and that will take a lot of time. Is there a quick way to find out which field is causing the problem with UNION ALL?

EDIT: Solved and uncovered another problem. I took Gordon's idea of running the queries as separate INSERT operations instead of using UNION ALL. I then iterated through each field in the query, doing a separate insert to find the field that was causing the conversion error, using this code:

Sub findProblemField()

Dim qdf As QueryDef
Dim sql As String
Dim fld As Field   

For Each qdf In CurrentDb.QueryDefs
    If InStr(qdf.Name, "out|") Then
        For Each fld In qdf.Fields
            sql = "insert into outrawtbl select top 1 " & _
                    "[" & qdf.Name & "].[" & fld.Name & "] from [" & qdf.Name & "]"
            CurrentDb.Execute sql, dbFailOnError
        Next
    End If
Next

End Sub

This led me to discover that one of the fields that is a string in the SELECT query is a Date/Time in the destination field, and a blank string value is what's throwing the error. Working on resolving this now...

4

1 回答 1

4

我不知道为什么 MS Access 会失败,union all但不会失败union。它应该产生相同的数据。我也不知道为什么在一种情况下会截断备忘录字段,而在另一种情况下不会。

但是,解决问题的最简单方法union all是进行两次插入:

INSERT INTO outRawTbl
select * from [out|noRFI_BS_noRT];

insert into outRawTbl
select * from [out|noRFI_BS_RT];
于 2013-05-08T01:03:20.620 回答