views:

69

answers:

1

Scenario

I have a database made up of 4 columns and 6 million rows. I want to be able to be able to use Excel to query this data in the same way in which I can query it using the Sql Server Management Studio.

I've had a google around and read a few articles but in all honesty I dont really know enough about the implementation to really know what to look for in a tutorial.

Question

Could someone please explain to me the way in which this works and how I might go about implementing what seems like a fairly simple idea?

EDIT:

So for example - I have a few simple queries that I want to run on this data. How do I go about setting these up? Is the idea that all of the data is first loaded into the excel sheet (or at least linked to the excel sheet so that the user can select the data to view on the fly?) - I cannot physically load in 6 million rows as Excel cannot take that level of data.....

A: 

Definitely don't pull all the data into Excel, that will bring it to its knees.

Normally, when I need an Excel (VBA) workbook to retrieve some data from a database, I will just have Excel connect to the database with the appropriate connection string, pass the SQL query string to the database, and retrieve the returned records. Below is some sample VBA code that retrieves some information from an MS Access database.

txtQueryString = "SELECT * " 
    & "FROM myDataTable " _
    & "WHERE fld1 = '" & myCriteria & "'"

txtConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & dbPathString & ";" _
& "Persist Security Info=False"

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open txtQueryString, txtConnectString, adOpenKeyset, adLockReadOnly, adCmdText

myData1 = rst.Fields("fld1").Value 
myData2 = rst.Fields("fld2").Value 
   .
   .
   .
    rst.Close
    Set rst = Nothing

The connection string to SQL Server will be different. I use this website for all my connection string needs.

Stewbob