比如有一个Column为A,要删掉值不为array(i)的field,array(i)是在combo中输入的,个数不定。sql要写成delete form table1 where A<>array(0) and A<>array(1)...
我该怎么写呢?请各位帮一把。

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim arrValue() As String
        Dim strValue   As String
        Dim strSql     As String
        ReDim Preserve arrValue(5)
        arrValue(0) = "'Value0'"
        arrValue(1) = "'Value1'"
        arrValue(2) = "'Value2'"
        arrValue(3) = "'Value3'"
        arrValue(4) = "'Value4'"
        strValue = Join(arrValue, ",")
        strValue = Left(strValue, Len(strValue) - 1)
        strSql = "ColumnA NOT IN (" & strValue & ")"
        Debug.Print strSql
    End Sub打印结果是
    ColumnA NOT IN ('Value0','Value1','Value2','Value3','Value4')
    你自己根据需要进行修改吧
      

  2.   

    where A<>'ga0' and A<>'d1'...
    改成
    where A not in ('ga0', 'd1',...)
      

  3.   

    我用的是VB+Access,要求删掉某列的值不为数组array()中任一个元素的记录,
    array()是动态的,在程序运行中得到。这个sql的条件该怎样写呢?
      

  4.   

    Dim arrValue() As String
        Dim strValue   As String
        Dim strSql     As String
        ReDim Preserve arrValue(5)
        arrValue(0) = "'Value0'"
        arrValue(1) = "'Value1'"
        arrValue(2) = "'Value2'"
        arrValue(3) = "'Value3'"
        arrValue(4) = "'Value4'"
            
         strSql = "delete form table1 where "
        For i = 0 To UBound(arrValue)
          strSql = strSql + "A=" + arrValue(4)
          If i < UBound(arrValue) Then strSql = strSql + " or "
        Next i
        
        MsgBox strSql
      

  5.   


      dim lLen as integer
      dim strSql as string
      dim I as integer
     
      llen=ubound(arrvalue)
      
       For i = 0 To lLen
        If lLen = i Then
           strSql = strSql & arrvalue(i)
        Else
           strSql = strSql & arrvalue(i) & ","
        End If
      Next
      strSql = " delete form table1 where A not in(" & strSql & ")"