How do I get a count of database records?

View some of the Frequently Asked Questions to our support staff. Included are some tips and tricks making this forum ideal for users getting started with GoAnywhere MFT. Note: Users can reply to existing topics but only our support staff can add new topics to this forum.
1 post Page 1 of 1

Support_Duane

Support Specialist
Posts: 65
Joined: Thu Mar 05, 2009 3:49 pm

Post by Support_Duane » Fri Mar 06, 2009 12:38 pm
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>
             </query>
    </sql>
    <setVariable name="count" value="${data[1]}" />
1 post Page 1 of 1