Page 1 of 1

How do I get a count of database records?

Posted: Fri Mar 06, 2009 12:38 pm
by Support_Duane
To your project:
  • Add an SQL task and select the database resource you want to use.
  • Add a query element, and specify the following SQL statement. For example:
    select count(*) from libraryName.fileName
  • Specify a variable name in the Output Variable field (e.g. "data")
  • Then add a Set Variable task, found in the Miscellaneous folder.
  • Enter a variable name (call it "count" for now) and then using variable notation, specify column one of the rowset defined in the Output Variable above. (e.g. ${data[1]})
Now the variable count contains the number of records the query has returned. You can use this variable to conditionally execute/skip a task or module.

The snippet below shows what the project would look like:
Code: Select all
    <sql resourceId="resourceName">
            <query outputVariable="data">
                      <statement>select count(*) from table</statement>
    <setVariable name="count" value="${data[1]}" />