title: Inserting values into SQL Server table via VBA
body: <p>Suppose I have a table in Excel with two columns (Name, Rate) (say, this table's name <code>tExcel</code>). Table starts at cell (2,1), and Date is static (in cell (1,1))</p>
  
  <p>I want to insert those values into SQL Server 2008 <code>tRate</code> table with following logic</p>
  
  <pre><code>insert tRate(ID, Rate, Date)
     select 
         s.ObjectID, e.Rate, Date   -- date comes from cell(1,1). DateType is smalldatetime
     from 
        tExcel e, tSecurity s
     where 
        e.Name = s.Number
  </code></pre>
  
  <p>I've created a connection</p>
  
  <pre><code>Sub disp_cust()
  Dim adoCN As ADODB.Connection
  Dim sConnString As String
  Dim sSQL As String
  Dim lRow As Long, lCol As Long
  Set cn = New ADODB.Connection
  sConnString = "Provider=sqloledb;Server=xxx;Database=xxx;User Id=xxx;Password=xxx"
  Set adoCN = CreateObject("ADODB.Connection")
  adoCN.Open sConnString
  adoCN.Close
  Set adoCN = Nothing
  End Sub
  </code></pre>
  
  <p>Thanks for help.</p>
  
  <p><strong>EDIT to @jaimetotal answer</strong></p>
  
  <pre><code>sql= "insert tRate(ID, Rate, Date) SELECT s.ObjectId ," &amp; Replace(Row.Cells(2).Value, ",", ".") &amp; ",'" &amp; defaultDate &amp; "' FROM tSecurity s where s.number = '" &amp; row.Cells(1).Value &amp; "'; "
  </code></pre>