MAK
MAK

Reputation: 7260

Assign return value of DB2 query to variable

I have a file test.sh in which i have a query which gives me the count of total records in the table, as shown below:

Query:

echo db2 -x "select count(*) from testable”

Now I want to assign the whatever value it returns after executing it to the variable as totalRecords using the Unix Shell Script.

Upvotes: 0

Views: 3649

Answers (1)

proksch_ibm
proksch_ibm

Reputation: 278

#!/bin/bash

cnt=`db2 -x "select count(*) from syscat.tables" `

echo "Counter is:  ${cnt}"

Counter is: 474

Upvotes: 3

Related Questions