Export To SQL
Export To SQL DESCRIPTION: This macro exports stock daily data: FINRA Reg SHO Daily Files(FINRA/NASDAQ TRF Carteret) to SQL server. http://regsho.finra.org/regsho-Index.html Export To SQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | Sub ExportToSQL() 'String Connection To export To SQL Server Dim conn As New ADODB.Connection Dim i Dim lastRow As Integer Dim sDate Dim sSymbol Dim market Dim connectString Dim sShortInt Dim sShortexempt Dim sShortVol As String Set conn = New ADODB.Connection conn.Open "Provider=SQLOLEDB;Data Source=DESKTOP-TG65LTOSQL2014;Initial Catalog=MyDbase;Integrated Security=SSPI;" If conn.State = adStateClosed Then Debug.Print rs.State MsgBox "Problem opening connection, check connection string" End If With Sheets("Sheet1") lastRow = Cells(Rows.Count, "A").End(xlUp).Row For i = 1 To lastRow - 1 sDate = "‘" & .Cells(i, 1) & "‘," sSymbol = "‘" & .Cells(i, 2) & "‘," sShortInt = .Cells(i, 3) & "," sShortexempt = .Cells(i, 4) & "," sShortVol = .Cells(i, 5) & "," market = "‘" & .Cells(i, 6) & "‘" connectString = "insert into dbo.finra (Sdate, Ssymbol, Svolume, SExemptVolume, TotalVolume, market ) values (" & _ sDate & sSymbol & sShortInt & sShortexempt & sShortVol & market & ");" conn.Execute connectString Next i MsgBox "Completed", vbOKOnly conn.Close Set conn = Nothing End With End Sub |
Ratings:
Read More