Parameterizing Imports

Our command line import tool, irdbImports, provides a variety of methods for parameterizing your imports.

Command Line Parameters
First of all the command line parameters are available within the script as special variables, @param1, @param2, @param3 and so on, for each parameter. @param1 will generally be the name of the import script.

A script called param.imp with the following contents.
print ‘@param1 has a value of ‘ + @param1
print ‘@param2 has a value of ‘ + @param2

Will produce the following output when run with ..\irdbimport param1 100
@param1 has a value of param1.imp
@param2 has a value of 100

Parameterizing Connection Strings and Tables to Import
The connection string in the datasource command, can accept regular expressions as input. So you can just build up an expression using variables.

You can also use your existing variables in the import command by putting an extra @ in front of the variable. So if your variable was called @tablename you could use @@tablename

A script called param_example.imp with the following contents
datasource a1 = odbc ‘dsn=’ + @param2

import [@@param3] = a1.[@@param3]
import [table_@@param3] = a1.{select * from [@@param3] }

When run with ..\irdbimport32 param_example.imp ir_northwind orders 
Will import table orders from the 32 bit odbc datasource, and save it as orders and table_orders.

Running dynamically generated scripts using ScriptExec
You can dynamically generally complete programs and execute them using the scriptexec statement. The following example imports the Orders table from the ir_northwind odbc data source.

datasource a1 = odbc ‘dsn=ir_northwind’
declare @tableName as string
set @tableName = ‘Orders’
scriptExec ‘import [‘ + @tableName + ‘] = a1.[‘ + @tableName + ‘]’

%d bloggers like this: