User`s guide

6 Using Database Toolbox Functions
6-10
Create a Query Using a String
This example shows how to include a string in your SQL query using a Microsoft Access
database.
Connect to the Database
Connect to Microsoft Access using native ODBC. For example, the following code
assumes you are connecting to a data source named dbtoolboxdemo with a blank user
name and password.
conn = database.ODBCConnection('dbtoolboxdemo','','');
Create a Query Using a String
Select all records from the table productTable where the product description is
'Slinky'. Create an SQL query string sqlquery that embeds the product description
string into the SQL query string by using an extra pair of single quotes.
sqlquery = ['select * from productTable '...
'where productDescription = ''Slinky'''];
Or, you can write the SQL query as a concatenation of two strings using brackets.
sqlquery = ['select * from productTable '...
'where productDescription = ' '''Slinky'''];
Execute the Query
Execute the SQL query using the exec function and display the data using the fetch
function.
curs = exec(conn,sqlquery);
curs = fetch(curs);
curs.Data
ans =
[3.00] [400999.00] [1009.00] [17.00] 'Slinky'
Close the Cursor and Database Connection
close(curs)