我使用 UNION 语句来合并两个表的记录。问题是,当我使用此 UNION 时,长度超过 255 个字符的长字段将在第 255 个字符中被省略。 当我使用单个选择时,根本没有问题。我发现问题出在 UNION 语句上。如果我使用 union,所有问题都已解决,但我不想使用 UNION all。 有什么想法为什么会发生这种情况吗?我尝试过投射字段,但没有任何效果
对,255 个字符是限制。
使用第二个查询,您可以在需要时查找完整的备忘录。
但是,即使你可以直接将备注字段填充到 64K,查询也只能检索到 32K。
更糟糕的是,如果您使用 Rich Text Box 控件填充备注字段,您可以达到兆字节的字段内容大小,但仍然只检索前 32K。
为了避免这种情况,您可以使用 DLookup 来获取完整内容。现在,当内容小于32K时,调用DLookup是浪费时间;因此 DLookup 仅应在必要时使用。
这是实现这一目标的旧方法:
Public Function LookupMemo( _
ByVal strSource As String, _
ByVal strFieldID As String, _
ByVal strFieldMemo As String, _
ByRef lngID As Long, _
ByRef varMemo As Variant) _
As String
' Extracts without truncation to 32768 characters the ' content of a memo field in a query.
'
' Assumes proper wrapping of table/field names containing spaces
' like "[My field name]" and a single field unique numeric key.
'
' Typical usage (SQL):
'
' SELECT
' ID,
' LookupMemo("Table1", "ID", "MemoField", [ID], [MemoField]) AS FullMemo
' FROM
' Table1;
'
' 2003-12-29. Cactus Data ApS, CPH.
' Maximum length of string from memo field when retrieved in a query.
Const clngStrLen As Long = &H8000&
Dim strExpr As String
Dim strDomain As String
Dim strCriteria As String
Dim strMemo As String
Dim lngLen As Long
On Error GoTo Exit_LookupMemo
If Not IsNull(varMemo) Then
lngLen = Len(varMemo)
If lngLen < clngStrLen Then
' The memo field is not truncated.
strMemo = varMemo
ElseIf Len(strSource) > 0 And Len(strFieldID) > 0 And Len(strFieldMemo) > 0 Then
' The memo is probably truncated by the query.
' Lookup the full memo in strSource.
strExpr = strFieldMemo
strDomain = strSource
strCriteria = strFieldID & " = " & lngID & ""
strMemo = vbNullString & DLookup(strExpr, strDomain, strCriteria)
End If
Else
' Return empty string.
End If
LookupMemo = strMemo
Exit_LookupMemo:
Exit Function
Err_LookupMemo:
' Return empty string.
Resume Exit_LookupMemo
End Function
我使用了 UNION ALL 并按前四列排序