QW SQL Wizard: (January 4, 2010)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

QW SQL Wizard (January 4, 2010)

QWSQLWIZ allows you to create a connection to an external database, supply an SQL query, and link the resulting data into a Quality Window application for analysis. Once the query is saved into a Quality Window application, every time that Quality Window application is opened, the query will be performed live, and the data will be presented within Quality Window. The Quality Window application acts just like any other Quality Window application, and can even be opened in QWSetup and have specs and targets embedded for each field, as well as having calculated fields defined. Each time the application is opened, the data from the previous query is deleted and the new data is inserted. Run-time prompting is also supported within the query to allow the user to specify parameters to alter the query at run-time (eg Start and End times, Batch Numbers, Product name, etc).

QWSQLWIZ allows the user to define their database connection, their database query and their Quality Window application is 5 easy steps: 1- Databases Create the connection string to open an existing database 2- Tables Choose an existing database Table to work with 3- Fields Choose a set of fields within the Table to work with 4- Query Define an SQL query to access the database and Table 5- Finish Save the database definition into a new Quality Window application

Click on the Next button to access the Databases screen:

On the Databases screen, there are basically 4 methods to define the connection string to a database: 1- By Database File (Access, Excel) Click on this button if your database is a MS Access database or an Excel spreadsheet. A browse window will open and you can point directly to your file within your computer or on a shared computer. Once the file is selected, a new connection string will have been created automatically for you. Note that in order to use an Excel spreadsheet, the sheet must be organized in a specific manner: Each column in Row 1 must contain column names describing the data beneath. The data must follow in row 2 onwards. The sheet name becomes the Table name, and each column name becomes the Fields within the Table. An example of a connection string for Excel would look like this: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Sample.xls;Extended Properties="EXCEL 5.0;HDR=YES";Persist Security Info=False An example of a connection string to an Access database would look like this: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Production.mdb;Persist Security Info=False 2- By existing UDL file If your database administrator has already setup a Universal Data Link (UDL) file, you can click on this button to browse to the specific file. A UDL file will generally contain all of the necessary connection string information to connect to the database without the user having to know any of the details.

3- By existing QW Application If you have previously created a Quality Window application using QWSQLWIZ and want to later use the connection string in another query, you can click on this button which will extract the connection string and SQL statement, and can be a great time saver in defining a new Quality Window application. You will be prompted to browse to your Quality Window application (QWT) file, and QWSQLWIZ will then position you to the Query screen for further editing. 4- Build/Edit Connection String For all other databases, you can click on this button to manually create a connection string. You may need support from your database administrator in order to successfully fill in this screen. Basically, any database that is provided with an ADO driver, can be defined on this screen. Examples of such databases are: SQL Server, Oracle, MySQL, InSQL, dBase, Foxbase, MS Access, Excel, and many others. Again, you may require the help from your database administrator in order to have the proper security rights, UserID, Password, as well as knowing the proper connection options to use. You will note that the bottom portion of the Databases screen contains a list of common connection strings. If you like, you can highlight the text from one of them, and Copy and Paste into the connection string above, and then if needed, click on the Build/Edit Connection String button to further refine the connection string. The list of common connection strings are located in a file called C:\Busitech\QW50\QWSQLWIZ.TXT. If you like, you can change these using Notepad to include some of your company specific examples. Once a connection string has been entered, click on the Next button to go to the Tables screen:

If the connection to the database was successful, you should see a dropdown box where you can choose one of your existing Tables. Once chosen, you should see some sample data appear in the grid below. Click on the Next button to go to the Fields screen:

On this screen, you will be presented with a list of Fields from the Table selected on the previous screen. You can select the fields you want in your query, or unselect those that do not apply. Also, you can drag and drop the fields to re-order them (click on the gray numbers on the side to drag and drop). Once you have your fields selected, click on the Next button to go to the Query screen.

The Query screen contains many options which will be explained below. The large textbox will contain a default SQL query based on the Table name and Fields selected previously. This is a standard SQL query statement which you can modify. We suggest you search online for a good primer on using the SQL language to further develop your query. The basic SQL statement starts with the SELECT keyword followed by a list of fields. Notice that each field is enclosed within square brackets. This is optional, but needs to be used if any special characters are embedded within a field name. Following the list of fields is the FROM keyword, followed by the Table name. Again, the square brackets around the Table name is optional, but required if special characters are embedded. This is the basic SQL query in its simplest form. If you want to include ALL fields from the table, you can use an asterisk (*) instead of listing each individual field: SELECT * FROM [Widgets] Another useful keyword to add would be the WHERE clause, where you can restrict the rows returned from the query: SELECT * FROM [Widgets] WHERE [Plant] = Chicago The above query would only return records from the Chicago plant. If you like, you can alter the order of the records returned by sorting them using the ORDER BY keyword: SELECT * FROM [Widgets] WHERE [Plant] = Chicago ORDER BY [Date], [Time] The above query would then sort the records in Date/Time order. There are many other SQL keywords that you can use here such as JOIN, UNION, GROUP BY, HAVING, DISTINCT, but they are beyond the scope of this manual.

Note that each time you make a change to the query, the Execute button will display allowing you to test the query and see the changes in the grid below. If there are any syntax errors in the current SQL statement, an appropriate message will be displayed. The basic idea with this screen is to form an SQL statement that fills the grid below in such a way that the grid would represent your new Quality Window application layout. As you know, all Quality Window applications require the first two fields to be a Date and a Time. You will notice 2 dropdown boxes on the right side of this screen. If your data contains Date/Time information, you can select each field from the combo whereby Quality Window will use these Dates/Times in the application. If you leave them blank, Quality Window will create its own Dates/Times based on todays date. Use the Transpose option if your data is laid out in such a way that it has 1 or more grouping fields, followed by a value, and you would like to pivot this data so that each unique value from the grouping field becomes a field in the resulting dataset. For example, assume you have data similar to the following: Date 2009-01-01 2009-01-01 2009-01-01 2009-01-01 2009-01-01 2009-01-01 2009-01-01 2009-01-01 2009-01-01 Time 01:00:00 01:00:00 01:00:00 02:00:00 02:00:00 02:00:00 03:00:00 03:00:00 03:00:00 Tagname pH Viscosity Temperature pH Viscosity Temperature pH Viscosity Temperature Value 7.64 13.79 15.61 7.99 13.59 15.87 7.88 13.66 15.77

If the Transpose option were selected on this recordset, the resulting recordset would look as follows: Date 2009-01-01 2009-01-01 2009:01-01 Time 01:00:00 02:00:00 03:00:00 pH 7.64 7.99 7.88 Viscosity 13.79 13.59 13.66 Temperature 15.61 15.87 15.77

Note that the original recordset should be first sorted by the grouping fields to get proper results. This can be done by specifying an ORDER BY clause in SQL: SELECT [Date],[Time],[Tagname],[Value] FROM [Widgets] ORDER BY [Date],[Time],[Tagname] As you can see, the second recordset is much more conducive to analyzing data within Quality Window, both in terms of displaying control charts, as well as calculating statistics.

Use the Extrapolate option if you have null values in your data, and you would like to carry the last non-null value in a field forward until the next non-value, so as not to have any null values. The button marked TABLES allows you to display all of the fields within the current Table, or any other tables in the current database. The idea here is to first position the cursor inside the SQL statement where you would like to insert a Table name or Field name from the displayed list, making it easy to build your SQL statement without introducing typing errors. The following screen shows an example of the TABLES screen:

Note that you can paste either the current Table, or paste the current Field (displayed to the right). You can click on any field to make it current. In this example, clicking on the Paste Field button would insert [Color_b] into the SQL statement, wherever the cursor was located prior to clicking on the TABLES button. You can leave this screen floating above the main screen as you build your SQL statement, or you can close it and re-open it at any time.

The PROMPT button allows you to add user prompts to fill-in your SQL statement at run-time. Suppose you wanted to have a query where you only wanted specific Plants included in the query. You would enter the following query: SELECT [Date], [Time], [Plant], [Product], [Line], [pH], [Viscosity], [Color_L], [Color_a] FROM [Widgets] WHERE [Plant] = And place your cursor just after the equal sign = and then click on the PROMPT button. The screen that pops up will allow you to build a prompt statement and include it within your SQL statement:

In this example, we chose MULTI as the type of prompt, which will basically display a list of Plant names with a checkbox beside each. We enter the caption Please select one or more Plants which will display at run-time to guide the user. We set Required = True so that the user must check at least one Plant in order to continue. We set Format = Text so that the prompting engine will return single quotes around the selected data. And finally, we enter an SQL statement that we would like to execute in order to return a list of all unique Plant names: SELECT DISTINCT [Plant] FROM [Widgets] After pressing the Ok button, the following would be displayed in the SQL statement window:

Notice the new code pasted after the equal sign. It begins with <PROMPT and ends with />. Note that at any time you can modify the prompt by first clicking anywhere inside of the prompt string and clicking on the PROMPT button again. You may have as many prompt statements as you wish in your query. Now click on the Execute button to see what happens:

A run-time screen appears prompting the user to select one or more Plants. Once selected and the Ok button is pressed, the SQL query will use the information in this prompt to select the specified records. Other types of Prompts are the COMBO and the LIKE type. COMBO is similar to the MULTI type, but instead loads a dropdown box for the user to select a single item. Note that you may also specify a Default Value if you wish. LIKE allows you to enter a search pattern at run-time for record matching. Whatever the user types in, it will perform a search for that field, and return all records that have that search item within the value. For example, a user could type in CHICA and all records for Chicago would be returned. Note that for LIKE to work properly, you must use the LIKE keyword in the SQL statement, instead of the Equals sign: SELECT [Date], [Time], [Plant], [Product], [Line], [pH], [Viscosity], [Color_L], [Color_a] FROM [Widgets] WHERE [Plant] LIKE Depending on the database, you may need to change the Wildcard character from % to * check your database manual for details.

Once you are happy with the results from your Query screen, click on the Next button to go to the Finish screen.

This screen allows you to port the data over to a Quality Window application. You can enter a more descriptive title for the generated application if you wish. Clicking on the Preview in QW button will execute the current SQL query, prompt the user if any prompting information was specified, and generate a new but temporary Quality Window application for you to view within Quality Window. When you close Quality Window, both the data and the Quality Window application will be deleted. This option allows you test out your new query without permanently creating the application.

Once you are satisfied with your results, you can click on the Save as QWT button to permanently create the Quality Window application. You will be prompted for a filename and location to store the application. You have just completed your first Quality Window SQL application. Now open Quality Window and from the Open screen, browse to the new application you just created. The screen should look something like this:

Make your selection, and you should see an SQL processing screen that looks like this:

Followed by all of the resulting data in your Logsheet:

At this point, you can hand off the Quality Window application to your users, or you can go into QWSetup and add specs and targets to each of the fields, or even add some new calculated fields. Note that if you open the application in QWSetup, be aware that all fields originating from the SQL query will have their exact field names entered in the XREF property of the corresponding field. This is how Quality Window manages the data returned from the query and where to place them in the application. Also, because of this, you can freely move your fields around in QWSetup without having to change the original query. You can also rename your Fields in QWSetup to make them more readable, as long as you keep the XREF untouched. Also note that the generated application has field lengths defined based on the returned data from the query at time of generation. You should review these lengths in QWSetup and extend any of them if necessary. If you have any questions about QWSQLWIZ, please contact Busitech at [email protected] or visit our website at www.Busitech.com

You might also like