19
SQLVB Report Tool – Russell Frearson and Kamu Nyambe User / Training Manual 5/30/2015 Russell Frearson Kamu Nyambe

User Manual_SQLVB Report Tool v2

Embed Size (px)

Citation preview

SQLVB Report Tool – Russell Frearson and Kamu NyambeUser / Training Manual

5/30/2015Russell FrearsonKamu Nyambe

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

ContentsThe SQLVB Report Tool..........................................................................................................................3

Current Version.................................................................................................................................3

Data Formats.........................................................................................................................................3

Import................................................................................................................................................3

CSV.................................................................................................................................................3

ODBC Connections.........................................................................................................................3

Intermediary Software...................................................................................................................3

Export................................................................................................................................................3

Exploring the GUI...................................................................................................................................4

Getting Stated........................................................................................................................................5

Installation.........................................................................................................................................5

Using the SQLVB Report Tool............................................................................................................5

Creating a database...........................................................................................................................5

Importing data into a database.........................................................................................................6

Registering a Data Source..................................................................................................................9

SCENARIO: Running a report from a database registered with the tool..........................................11

Exploring the Query Editor..........................................................................................................13

2 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

The SQLVB Report ToolThe purpose of this tool is to process SQL scripts for the purpose of producing customised reports. The reports generated can be output to MS Excel.

The user of this tool can create reusable queries for a listed database or databases for their own use or a third parties use in the administration of a database as well as run ad hoc queries that may not require saving.

Current VersionThe initial tool was developed to accept the .mdb file format. After 2007, the .accdb format was released as an upgrade to the .mdb format. This upgrade prompted a need for a uniform upgrade of the report tool. Whilst the current version has been upgraded to accept .accdb files, it is backwardly compatible to work with .mdb files. This compatibility is made possible due to the use of the Data Access Object which has the ability to interface with both .mdb and .accdb.

Note the above only applies if a user has database components of Microsoft Office 2010 installed on their computer as from Access 2013 on the use of the “*.mdb” file format was deprecated and only databases using the 2007 – 2013 “*.accdb” format were supported.

Data FormatsThis section explores the different formats of data that are compatible with the report tool. This tool

is primarily developed to interact with various structured data persistence stores.

ImportThe following formats are acceptable for importing data into the tool:

CSVComma Separated value files serve as a common means of data storage and transfer between databases. Once imported into the report tool, an existing database can be populated with data contained in the CSV file.

ODBC ConnectionsThe report tool has the capability to connect to a network database provided that it hosted on the same network and the appropriate file access permissions have been granted. Typically this connection is performed through the Data Access Object with preconfigured access parameters.

Intermediary SoftwareIntermediary software such connx32 serve as a means of facilitating communication between an application and a particular database, whilst encapsulating the overall current state of the database. The report tool has been used to access data using connx32 and was the first use for the tool.

ExportThe report tool’s primary function is to output data to a Microsoft Excel spreadsheet for various reporting purposes. However, if required the output can be presented in any of the formats mentioned in the import section above.

3 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

Exploring the GUIThe main interface of the report tool is shown below.

4 | P a g e

Database Name: This displays the name of the database that is currently open.

Linked Table: This contains a list of tables linked to the database that is currently open.

Quick Query Pick: This contains a list saved queries relating to the database that is currently open.

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

Getting StatedThis section is structured in a tutorial format, and is intend as both a step-by-step practical guide and reference manual.

Installation To install this tool, run “Project IT.msi” on the CD provided. The entries for the sample programs provided use the path “C:\PROGRAM FILES\SQLQURY\” the default path for setup. If the user nominates another path during installation then the path references for the sample programs will have to change.

After installation the user can create a shortcut to the desktop using the supplied icon.

If the sample programs aren’t required deleting the file register .accdb before starting the program will generate an empty program database.

Using the SQLVB Report Tool The following files have been provided to assist with getting an understanding using the report tool.

Project_Reports.accdb Projects_1065.accdb Project_Tasks.accdb Activity_codes.csv All_Projects.sqv

For training purposes, please copy the “SQL_Test” folder provided with this manual to your C drive. It is recommended to maintain a consistent file structure to group all components used when creating queries. The recommended file structure is as follows:

C:\SQL_Test\Databases C:\SQL_Test\CSV C:\SQL_Test\Spread_Sheets C:\SQL_Test\Script_Files C:\SQL_Test\User Manual

Creating a databaseThe report tool is packaged with a system database. The system database is a vital component as it ensures that the report tool is scalable, albeit within the constraints of its intended functionality. The following three tables make up the system database:

TABLE NAME INFORMATION STORED RELATIONSHIPSODBCTypes Stores the type of drivers available “Name” is foreign key in DbaseDbase Stores all databases used by the tool “Name” is foreign key in

SaveQrySaveQry Stores all saved queries associated with a

database

5 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

Please take the following steps to create a database.

1. From the menu bar, navigate to Database Listing ->Create New Database(*.accdb)

2. In the dialog box that opens, enter the name of the database to create. In this case the name of the database is “tutorial.accdb”. Please ensure that the .accdb file extension in present in the filename.

Enter a file path for the new database. This is where the database will be stored. Use the “Browse for File Path” button to locate the database folder that was previously copied to the C drive; C:\SQL_Test\databases\.

Click on “Create Database” to create the new database.

3. The following message will be displayed to confirm that the database has been created:

Click “OK”, and then click “Close” to exit the “Create an Access Database” dialog.

Importing data into a databaseOnce a database has been created, it is immediately available for use. Initially, a new database is just an empty container and would need data to be inserted from either a linked file or a script file setting up a database. This section will demonstrate the process of importing data into a new database. The same process would apply when importing data into a pre-existing database.

6 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

The first step required is to open a database:

1. From the menu bar, navigate to Database Listing ->Open Listed Database

2. A dialog box listing all registered databases is presented. Locate the database required, which in this case is the “tutorial.accdb” that was previously created.

3. Click on the database to select it, and then click on the “Open Database” button.4. Click “Close” to dismiss the dialog box. Notice that the “Database name” filed is now

populated with the URL to the recently opened database.

Once the database has been opened, a link must be created to establish a connection between the database and the source of the required data. The data source must be registered prior importing data from it. The section titled “Registering a Data Source” demonstrates the process of registering a new data source.

If the database opened has pre-existing links and provided that its location has not changed then there is no requirement to re-establish these links.

Note: Linking to a database does not establish a connection to all its tables. Each table inside the database must have its own link created.

7 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

Follow these steps to link the database to a data source:

1. From the menu bar, navigate to Link Tables ->Link a table to Open Database

2. A dialog box listing all the available data sources will be presented.

3. Click on the “Project_Reports.mdb” to select it. 4. Once a table is selected, the drop-down list below the list of data sources is populated with a

list of tables contained in that data source. Click on the drop-down arrow to show the tables, and select “BEPL_Projects”.

8 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

5. Click on “Link Table” and then “Close” to dismiss the dialog. The linked table will now be available for use from the “Linked Tables” drop-down list.

Hint: The name of the linked table will be prefixed by the letters “lnk”. In this case the linked table is “lnkBEPL_Projects”.

Registering a Data SourcePre-existing databases and other data sources can be added to the tool.

1. From the menu bar, navigate to Database Listing ->Add New or Edit Registration.

2. The following dialog box is presented:

9 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

3. Click “Add”. Populate the form as shown below:

10 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

Hint: Use the “Browse for File” button to locate the data source.

4. Click “Save” and then “Close” to dismiss the dialog.

As an example of a data source the following shows the registration details for the “Connx” software product that acts as an intermediary that provides the ability to connect to a database and pass through an SQL query from a host and return the resulting data set.

11 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

SCENARIO: Running a report from a database registered with the tool.

This section assumes that the reader has read the sections “Creating a Database” and “Importing Data into a New Database”. In a typical scenario, database tasks that that are performed using this tool are recurring tasks. This raises a need to save the queries required to perform these tasks for reuse. For the purpose of this demonstration a saved query is provided in a script file named “All_Projects.sqv”.

Note that a query can only be run by the database that contains the table and linked tables used by the script file.

The query inside the script file is systematically structured to:

Drop all reusable tables Recreate all reusable tables Populate the newly created tables Query the tables to manipulate the data returned Produce a report

12 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

To produce a report using a saved query:

1. Open the “Project_Reports.accdb” database2. Link to the “BEPL_Projects” table from the “Projects_1065.accdb” database.3. Select the linked table from the “linked tables” dialog4. From the menu bar, navigate to Queries -> Open an Existing Query

5. A dialog is presented for you to locate the query. Enter the necessary information if required.

6. Click “Open Query”. 7. The query editor is pre-populated and displayed. The editor is pre-populated with the

database, tables and the saved query.

Examining the Saved QueryIn the script file “All_Projects.sqv” there are commands the reporting tool uses to identify the spreadsheet and the worksheet to write data to.

To identify the spreadsheet DDE Excel C:\SQL_Test\Spreadsheets\Projects_All.xls ;

To identify the worksheet DDE Excel_Sheet Hours;

13 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

The information below is provided as examples of formatting commands that the program can use to enhance the reporting of data from a query.

The command below adds a header to the data.

DDE Add_Header 1 , Project , Week 1 , Week 2 , Week 3 , Week 4 , Week 5 , , Totals , ;

There are also commands like the one below which will sum all columns of data horizontally between rows 2 to 6.

DDE Total_Rows Total_Rows_1, 2 , 6 ;

And another command like the one below which will sum all columns of data vertically from column 2 to 8

DDE Sum_Rows 1 , 2 , 8 , Total Hours , ;

In another spreadsheet :

DDE Excel_Sheet Week1

There are extra commands like the one below which will sum columns 7 to 14 on each change of value in column 1 of the report.

DDE Sum_On_Change 1,7, 14 , Total for Project ;

And another command which will total all hours charged to the project from column 7 to 14

DDE Total_Sum_Change 7, 14, Total Hours for all Projects, ;

The tool can identify these and other commands in the script file and process them as it is writing data to the spreadsheet.

14 | P a g e

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

If required the saved query can be edited and saved using the tools available in the text editor.

15 | P a g e

Exploring the Query EditorDefault Database Name: the name of the database that is opened.

Query Rows Transferred: this is a progress indicator during query execution

Tables: contains a list of linked tables

Add Table to Query: adds selected table to query window.

Fields: Contains all the fields from the selected table

Add Field to Query: adds selected field to query window

Add Comma: add a comma to the query inside the query window

SQLVB Report Tool – Russell Frearson and Kamu Nyambe

8. From the menu bar on the text editor navigate to Process Scripts -> Run DDE

9. The following output will be produced:

16 | P a g e