我用TDBGrid显示,如果两个文本型字段中的名称相似度在50%-100%显示在一起,请问如果不在Access中建立查询,该怎么写SQL又怎样写函数,相似度的限定最好在程序中能设置,请哪位大哥费心费事给写段代码。我这有段相似度要求很低的匹配函数测试没问题,不知能不能改一改,我真的很需要这段代码,请好心人帮忙,不胜感激!!!SELECT * FROM CompareBase INNER JOIN Zd_yp5 ON AlikePercentEx(CompareBase.Xm_name,zd_yp5.yp_name); 
Public Function AlikePercentEx(ByVal strTextSrc As String, _ 
                                                            ByVal strTextDest As String, _ 
                                                            Optional ByVal blnCaseSensitive As Boolean = False, _ 
                                                            Optional ByVal blnExactPositionMatch As Boolean = False) As Double 
             
          Dim o_strTextSrc     As String 
          Dim o_strTextDest     As String 
             
          Dim o_strTextLonger     As String 
          Dim o_strTextShorter     As String 
             
          Dim o_strByteSrc     As String 
          Dim o_strByteDest     As String 
          Dim o_lngLength     As Long 
          Dim o_lngItems     As Long 
          Dim o_lngMatches     As Long 
          Dim o_lngStart     As Long 
             
          If Not blnCaseSensitive Then 
                  o_strTextSrc = UCase(strTextSrc) 
                  o_strTextDest = UCase(strTextDest) 
          Else 
          End If 
             
             
          If o_strTextSrc = o_strTextDest Then            '如果一致 
                     
                  AlikePercentEx = 100# 
             
          Else 
             
                  If Len(o_strTextSrc) = Len(o_strTextDest) Then 
                          o_strTextLonger = o_strTextSrc 
                          o_strTextShorter = o_strTextDest 
                  ElseIf Len(o_strTextSrc)  > Len(o_strTextDest) Then 
                          o_strTextLonger = o_strTextSrc 
                          o_strTextShorter = o_strTextDest 
                  Else 
                          o_strTextLonger = o_strTextDest 
                          o_strTextShorter = o_strTextSrc 
                  End If 
                                     
                  o_lngLength = Len(o_strTextShorter) 
                                     
                     
                  o_lngStart = InStr(o_strTextLonger, Left(o_strTextShorter, 1)) 
                     
                  If o_lngStart Then 
                     
                          o_lngMatches = 1 
                     
                          For o_lngItems = o_lngStart + 1 To Len(o_strTextLonger) 
                                     
                                  If blnExactPositionMatch Then        '位置必须一致 
                                          o_strByteSrc = Mid(o_strTextLonger, o_lngItems, 1) 
                                          o_strByteDest = Mid(o_strTextShorter, o_lngItems - o_lngStart + 1, 1) 
                                             
                                          If o_strByteSrc = o_strByteDest Then 
                                                  o_lngMatches = o_lngMatches + 1 
                                          Else 
                                          End If 
                                     
                                  Else    '任意位置模糊匹配 
                                             
                                             
                                  End If 
                          Next 
                             
                          AlikePercentEx = (o_lngMatches / o_lngLength) * 100 \ 1 
                             
                  Else 
                             
                          AlikePercentEx = 0# 
                  End If 
                     
          End If 
    
  End Function