Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable
# 1  
Old 09-27-2010
Data Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All,

I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2.

I want to assign the output of a select count(*) from tablename to a unix variable in a shell script.

I am using ksh.

The database used to run the query is DB2 , please advise

Regards
Siddarth
# 2  
Old 09-27-2010
please try var='select count(*) from tablename' and then the database connection points
# 3  
Old 09-27-2010
Hi,

I have already tried that and it didnt work before.

I am establishing a connection to the database at the very start of the script and running this query after a couple of commands.

This syntax doesnt assigns value to the variable
# 4  
Old 10-26-2010
Follow this format:

db2 connect to dbname...
myvar=$(db2 -x "select count(*) from schema.table")
print "myvar = $myvar"
db2 connect reset
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Script to take file count and insert into DB2 table

Team I have files in different directories . How can i take the count of latest file and insert into Db2 table . I am using awk 'END{print NR+1-ARGC}' (File name) to get the counts. How can i take 1.The count of latest file 2.Insert into Db2 table( File Name and Counts) . cd... (4 Replies)
Discussion started by: Perlbaby
4 Replies

2. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies

3. UNIX for Advanced & Expert Users

Using xml to run db2 commands

Hi, Strange problem I'm having here and not sure what to do. I have here a xml that is supposed to execute the next value in the schema but it isn't do the job it's supposed to do. I'm not a dba or a developer so I'm sorry in advance if there are some things i don't understand. when we run... (5 Replies)
Discussion started by: techy1
5 Replies

4. Shell Programming and Scripting

Run DB2 export command in loop

Hi All, I have list of 100 table names in a file, how to read table name from and pass to DB2 export command and run for all tables in loop. Please help me with script. db2 EXPORT TO ~/data_export/<table name from file>.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.<Table Name... (4 Replies)
Discussion started by: srimitta
4 Replies

5. UNIX for Dummies Questions & Answers

using unix variable in select column in awk

Hi, I have file on below pattern, and i want to write a generic awk to handle all cases. input_file: col1~col2~col3~col4~col5~col6 I need to generate 4 files something like this File1: col1~~col2~~col3 File2: col1~~col2~~col4 File3: col1~~col2~~col5 File4: col1~~col2~~col6 (1 Reply)
Discussion started by: luckybalaji
1 Replies

6. Shell Programming and Scripting

How to redirect value from sql select statment to unix variable

Hi, I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use.. Please can any body help me in this regards Thanks & Regards Abdul Hafeez Shaik (17 Replies)
Discussion started by: abdulhafeez
17 Replies

7. Shell Programming and Scripting

Storing count(*) into unix variable

Hi, I've just started on unix shell scripting a few days ago. I tried look for the solution to my problem over the net but to no avail. The objective of my script is to count the number of records in a particular table from a Oracle database. Ok, here's my problem, when I run this script: ... (1 Reply)
Discussion started by: mervinboyz
1 Replies

8. UNIX for Dummies Questions & Answers

select count(*) in sqlplus into variable unix shell

Need to select count(*) from table to check for zero result in unix script (2 Replies)
Discussion started by: struggle
2 Replies

9. Shell Programming and Scripting

DB2 and Unix Variable .....

Guys Quick help... ---------------------------- #!/usr/bin/ksh db2 -x "select count(*) from ${SCHEMA}.EMP"> $HOME/count.dat COUNT=`cat $HOME/count.dat` echo Table Count: $COUNT if ( $COUNT -eq 0 ); then echo Record Count in Table is 0 exit 1 fi echo Records Exist... (2 Replies)
Discussion started by: freakygs
2 Replies

10. Shell Programming and Scripting

select count(*) into a variable

Hi, Could anybody help me how can I assign the value of "select count(*) from table1" to a variable in an unix shell script. Thanks. (4 Replies)
Discussion started by: nguda
4 Replies
Login or Register to Ask a Question