Example of connecting to a relational database - Adventure Works

From XLCubedWiki

Jump to: navigation, search

This example uses the Adventure Works database and view vDemoView.

RelDB1.png


You can download the Excel workbook that is used in the example here File:ConnectRelationalDB.zip

Connecting to your own server and database

To connect to your server and copy of Adventure Works database perform the following steps:

        '=XL3QueryTableSetConnectionString("Results","QueryTable1",$B$17)

This will stop the workbook timing out as it tries to connect.

Using this workbook example

  =XL3QueryTableSetConnectionString("Results","QueryTable1",$B$17)

XL3QueryTableSetConnectionString will also be taking settings from cell B17 which hold further parameters such as server and database name.

       =XL3QueryTableSetSQL("Results","QueryTable1",$B$14)
     ="select * from dbo.vDemoView where region = '"&B7&"' and EnglishProductCategoryName= '"&B6&"'                   
      and IncomeGroup=  '"&B8&"' and monthyear='"&B11&"'"

The four cell locations in the SQL statement correspond to the five different filters. Cell B11 is combination of B9 and B10 (month and year) as this is held as one value in the database.

        ="DRIVER=SQL Server;Trusted_Connection=Yes;SERVER="&$B$3&";DATABASE="&$B$4&""


RelDB2.png


RelDB3.png



RelDB4.png



RelDB5.png


           =INDEX(Sheet3!F12:F14,Results!C6)
Personal tools
Namespaces
Variants
Actions
Follow XLCubed on Twitter XLCubed on LinkedIn Download

Navigation
Toolbox