How to assign record count output of isql to a shell variable ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to assign record count output of isql to a shell variable ?
# 1  
Old 04-27-2010
How to assign record count output of isql to a shell variable ?

isql
select count(*) from Table
eof


How to assign record count output of isql query to a shell variable ?
# 2  
Old 04-27-2010
Code:
variable=`isql << eof
select count(*) from Table
eof`

# 3  
Old 05-14-2010
How to assign record count of isql output to a shell variable ?

Quote:
Originally Posted by vidyadhar85
Code:
variable=`isql << eof
select count(*) from Table
eof`


Actually with this option, the variable gets the value like '(1 row affected)' or '(0 rows affected)'. But i need only the exact record count. How to achieve this..?
# 4  
Old 05-14-2010
Quote:
Originally Posted by vikram3.r
Actually with this option, the variable gets the value like '(1 row affected)' or '(0 rows affected)'. But i need only the exact record count. How to achieve this..?
In version 11.0.x and higher, specify "set nocount on" option to suppress the rows affected line.

In pre 11 versions, use sed to delete the lines that have the word "affected" in them.

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 5  
Old 05-26-2010
Quote:
Originally Posted by durden_tyler
In version 11.0.x and higher, specify "set nocount on" option to suppress the rows affected line.

In pre 11 versions, use sed to delete the lines that have the word "affected" in them.

tyler_durden

Is there any option like ,
establishing isql connection only once, and executing multiple queries and getting their respective record counts in separate variables...?
My need is like,
isql >>
recordcount1= query1
recordcount2= query2
>>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the output of a ISQL command in a variable?

I am trying to run a query which returns a sum value(a number). I want to get it in a variable so that i can refer to that variable in different places. when i am running the following command variable=`isql -Uuser -Sserver -Ppassword 1> select sum(count(*)) from xyz..abc where clm_id... (2 Replies)
Discussion started by: Sharma331
2 Replies

2. Shell Programming and Scripting

Return value inside isql to a shell variable in ksh

Hello, I have a shell script where I am doing an isql to select some records. the result i get from the select statement is directed to an output file. I want to assign the result to a Shell variable so that I can use the retrieved in another routine. e.g. "isql -U${USER} -P${PASSWD} -S${SERVER}... (1 Reply)
Discussion started by: RookieDev
1 Replies

3. Shell Programming and Scripting

How to assign value from isql to UNIX variable

I want output to be assigned to UNIX variables echo "Enter RRS ID: " read rrs isql -SPROD_DDS -USYBUSER -PSYBPASS -b -osfg.out << EOF use sip go set nocount on select issuerId, legalStructTxt, productName, issuerName from sf_product where rrsId = $rrs go EOF (1 Reply)
Discussion started by: JayDoshi
1 Replies

4. UNIX for Dummies Questions & Answers

how to use shell variable in isql

Hi , I want to use shell variable in isql. example.. $ksh ./sudh.ksh "2041qwer" sudh.ksh is my script passing the perameter "2041qwer" Code in my script : =========== $SYBASE/$SYBASE_OCS/bin/isql -I$SYBASE/interfaces -S$OTHRSRVR -U$SYBUSER -P$SYBPASS -w... (1 Reply)
Discussion started by: sudhakarpasala
1 Replies

5. Shell Programming and Scripting

Assign perl output to ksh shell variable

Hello, I am writing a ksh script on an AIX system. I need to get the date and time from a file into a variable. I found the following perl script from another post on this site and modified it slightly to output the format I need: perl -e '@d=localtime ((stat(shift)));... (4 Replies)
Discussion started by: swimp
4 Replies

6. Shell Programming and Scripting

Setting variable for query using iSql / Korn Shell

Hi All- First time using iSql. I have 4 query files - some have more than 1 line of sql statements After a bit of research it appears I can just use the -i command and specify the input file. Questions: Does it matter that there are multiple queries in each file? Do I need to have... (3 Replies)
Discussion started by: Cailet
3 Replies

7. Shell Programming and Scripting

Need help with Isql record count

What I am trying to do is check if the database query returned any records. If no records returned then output a message else output results to a file. Right now if I take out the if and else statements the code runs fine and sends the email. If no records returned the email sends the column... (4 Replies)
Discussion started by: johnu122
4 Replies

8. Shell Programming and Scripting

Setting value of Shell variable from within ISQL

Hi Guys, Need help. I am using ISQL inside a shell script. Is there a way to set the value of shell script variable from inside the ISQL code. I do not want to write the results from the SQL to an output file. Please let me know. Regards, Tipsy. (3 Replies)
Discussion started by: tipsy
3 Replies

9. Shell Programming and Scripting

how to assign sql output data to shell script variable

Hi Guys ! I am new to unix and want to find out how we can make sql statement data to shell script variable? Any help/suggestion is greatly appreciated -Chandra (1 Reply)
Discussion started by: kattics
1 Replies

10. UNIX for Dummies Questions & Answers

how to assign an output to a variable

Hi, I am giving a grep command, and i am getting the output. i want to store it in a variable for eg a = grep '12345' /dir/1/2/log.txt ( the output is number) b= grep 'basic' /dir/1/2/log1.txt (in this case the output is character) so how to assign the output of grep to a variable ... (1 Reply)
Discussion started by: vasikaran
1 Replies
Login or Register to Ask a Question