[英]How to perform case sensitive group by in MS Access
In MS Access database to find the mismatch (ie difference) records between two tables(Employee and Employee_PROD) I am using the UNION ALL . 在MS Access数据库中查找两个表(Employee和Employee_PROD)之间的不匹配(即差异)记录,我正在使用UNION ALL 。 The query is as follows:
查询如下:
SELECT [COMPANY],[DEPT],[DOJ],[EMP_ID],[Name],[SUB_COMPANY] FROM
(SELECT '[Employee]' AS TableName,[COMPANY],[DEPT],[DOJ],[EMP_ID],[Name],[SUB_COMPANY] FROM [Employee]
UNION ALL
SELECT '[Employee_PROD]' AS TableName,[COMPANY],[DEPT],[DOJ],[EMP_ID],[Name],[SUB_COMPANY] FROM [Employee_PROD] )
GROUP BY [COMPANY],[DEPT],[DOJ],[EMP_ID],[Name],[SUB_COMPANY]
HAVING COUNT(*) = 1 AND MIN(TableName) = '[Employee]'
The problem I am facing is that the GROUP BY
is not considering the case sensitivity. 我面临的问题是
GROUP BY
没有考虑区分大小写。 For example " a ndrew" and " A ndrew" is treated as same. 例如,“ 一个 ndrew”和“ 一个 ndrew”被视为相同。 I want to perform group by with case sensitive to find the difference records.
我想区分大小写执行分组查找差异记录。
Is there any way to do the same in MS Access? 有什么方法可以在MS Access中执行相同的操作?
Is there any other approach to find the differences between two tables having same column names, data types and the number of records is 7,00, 000? 还有其他方法可以找到具有相同列名,数据类型和记录数为7,00,000的两个表之间的差异吗?
I have tried the following: 我尝试了以下方法:
DataTable
and then find the difference. DataTable
加载到DataTable
,然后找到差异。 Got out of memory exception due to huge amount of data. NOT EXISTS
to compare the rows. NOT EXISTS
比较行。 The query got hanged and the execution never completed. UNION ALL
approach is working but the issue is that GROUP BY
is not considering the case sensitivity. UNION ALL
方法有效,但是问题在于GROUP BY
没有考虑大小写敏感性。 You could group by the byte value: 您可以按字节值分组:
? StrToByte("Andrew")
416E64726577
? StrToByte("andrew")
616E64726577
though it might be a bit slow with the large amount of data you have. 尽管您拥有大量数据可能会有点慢。
Public Function StrToByte(ByVal strChars As String) As String
Dim abytChar() As Byte
Dim lngChar As Long
Dim strByte As String
abytChar() = StrConv(strChars, vbFromUnicode)
strByte = Space(2 * (1 + UBound(abytChar) - LBound(abytChar)))
For lngChar = LBound(abytChar) To UBound(abytChar)
Mid(strByte, 1 + 2 * lngChar) = Hex(abytChar(lngChar))
Next
StrToByte = strByte
End Function
For SQL only, and if you only about the first character, try: 仅对于SQL,并且如果仅关于第一个字符,请尝试:
GROUP BY [COMPANY],[DEPT],[DOJ],[EMP_ID],[Name], ASC([Name]),[SUB_COMPANY]
Can you not specify OPTION COMPARE BINARY in a module to perform a case sensitive search? 您是否不能在模块中指定OPTION COMPARE BINARY来执行区分大小写的搜索?
This thread https://access-programmers.co.uk/forums/showthread.php?t=33962 and this one How to write Case Sensitive Query for MS Access? 该线程https://access-programmers.co.uk/forums/showthread.php?t=33962以及该如何编写区分大小写的MS Access查询? both describe different methods.
两者都描述了不同的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.