DBQUERY

The DBQUERY function executes an SQL statement against a database. The SQL statement can be any permitted by your database management system or ODBC driver.

When the DBQUERY function is used in a map, the default OnSuccess action is adapter specific. The default OnFailure action is to rollback any changes made during map processing. The default Scope will be integral unless the map is defined to run in bursts (which is the case when one or more inputs have the FetchAs property set to Burst).

There are two ways to specify the arguments for DBQUERY. You can use DBQUERY [Meaning 1] to execute an SQL statement when you want to look up information in a database using a parameterized query that is based on another value in your data. If your SQL statement is a SELECT statement, the DBQUERY function might be used in conjunction with the RUN function to issue dynamic SELECT statements whose results can be used as input to another map.

You can also use the DBQUERY function [Meaning 2] to execute an SQL statement when the database, table, or other database parameters might vary; perhaps being supplied by a parameter file.

Syntax:

DBQUERY (single-text-expression , single-text-expression ,
[ single-text-literal ] )

Meaning:
  1. DBQUERY (SQL_statement , mdq_filename , database_name)
  2. DBQUERY ( SQL_statement , parameters )
Returns:
A single text item

If your SQL statement is a SELECT statement, the results of the query in the same format as a query specified as a map input card, including row delimiters and terminators, and so on.

If your SQL statement is anything other than a SELECT statement, "none".

Arguments for meaning 1

DBQUERY (SQL_statement , mdq_filename , database_name)

Arguments for meaning 2

DBQUERY ( SQL_statement , parameters )

When used with Meaning 2, DBQUERY must conform to these rules:

Examples

Assume that you have a table named "PARTS" that contains the following data:
PART_NUMBER PART_NAME
1 1/4" x 3" Bolt
2 1/4" x 4" Bolt

Also assume that this database has been defined using the Database Interface Designer in a file named mytest.mdq and that the name of the database, as specified in the .mdq file, is PartsDB.

DBQUERY ( "SELECT * from PARTS" , "mytest.mdq" , "PartsDB" )

Returns 1|¼" x 3" Bolt<cr><lf>2|¼" x 4" Bolt<cr><lf>

where <cr><lf> is a carriage return followed by a line feed.

Using Meaning 2, you can also specify the DBQUERY this way:

DBQUERY ( "SELECT * from PARTS" , "-MDQ mytest.mdq -DBNAME PartsDB" )

where both the .mdq file name and database name are specified.

Or, specify it this way, using Meaning 2 by specifying the database type and the appropriate database-specific parameters:

DBQUERY ( "SELECT * from PARTS" , "-DBTYPE ORACLE -CONNECT MyDB -USER janes" )

Assume that you have an input file containing one order record. To map that order to another proprietary format, you also have a parts table with pricing information for every part for every customer, a very large table. Rather than using the entire parts table as the input to your map, you might use the RUN function with a DBQUERY to dynamically select only those rows from the parts table corresponding to the customer in the order file, as follows:

RUN ( "MapOrder.MMC" ,
  "IE2" + DBQUERY ( "SELECT * FROM Parts WHERE CustID = "
 + CustomerNo:OrderRecord:OrderFile + " ORDER BY PartNo" ,
"PartsDB.MDQ", "PartsDatabase" ) )

Related functions