简单,可复制

点点滴滴,尽在文中

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

只做备注

Sub general_sql_macro()
   Sql = ""
   column_name = "user_count"
   Sql = "insert into `mytable` (date," + column_name + ") values "
   
    For Row = 1 To 1000
        date_str = CStr(Sheets("Sheet1").Cells(Row, 1).Value)
        If date_str = "" Then
           Exit For
        End If
        If Row <> 1 Then
          Sql = Sql + ","
        End If
        Value = Sheets("Sheet1").Cells(Row, 2).Value
      
         insert_value = "('" + date_str + "'," + CStr(Value) + ")"
         Sql = Sql + insert_value
        
    Next Row
    Sql = Sql + " on DUPLICATE KEY UPDATE " + column_name + "=values(" + column_name + ")"
    Sheets("Sheet1").Cells(5, 5).Value = Sql
    
End Sub

 

posted on 2013-10-23 13:18  ggjucheng  阅读(1129)  评论(0编辑  收藏  举报