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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the output of a ISQL command in a variable?
# 1  
Old 06-27-2014
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
Code:
  variable=`isql -Uuser -Sserver -Ppassword
1> select sum(count(*)) from xyz..abc where clm_id in(43517830,80226100,340223200,70217600,400222400,720221500,920220600,970226100,990223800) group by clm_id
2> go`

The output of the variable comes as below
Code:
 ksh[4]: 0403-057 Syntax error: `(' is not expected.

while i am expecting output as 58.

what should i do please suggest.

Thanks
# 2  
Old 06-27-2014
Maybe saying more about your system (OS + version and shell you use) may help us understand...
ksh standard syntax for giving values to a variable which comes from some sort of command execution is:
Code:
 VAR=$( command...)

and so using "(" etc will be interpreted by the shell...
This User Gave Thanks to vbe For This Post:
# 3  
Old 06-27-2014
Ive got a feeling your attempt will not work also because not on one line only...

I would suggest you to use in your script a heredoc which calls sql...

This is what I do with SQL (oracle) for example:
Code:
your_script
.
.
# call your sqlcode
sqlplus -silent user/passwd <<END
start $HOME/test.sql
exit;
END

# continue with your script
.
.

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 handle NULL value output from ISQL command?

I am using ISQL command in ksh script. Suppose if i get NULL value from the query which i run,how can i handle it? I am getting a NULL result set and the following error is coming. ############### output of isql command for getting the sum of JEs ################ ----------- NULL... (4 Replies)
Discussion started by: Sharma331
4 Replies

2. 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

3. Shell Programming and Scripting

Issue with redirecting a ISQL output to a file

Hi all, I have wrote a script to redirect the output of Sybase query to a file. Its a single XML message i am fetching with sybase query. The problem i faced here is the XML message line crosses the normal line limit in unix. Could some please help me how to get complete xml message... (1 Reply)
Discussion started by: ravin
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

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 ? (4 Replies)
Discussion started by: vikram3.r
4 Replies

6. Shell Programming and Scripting

Extract resultset numeric value from isql output ?

isql output comes as below, (0 rows affected) (1 row affected) (7 rows affected) How to extract the resultset number alone from the particular line ?? such as 0 1 7 (3 Replies)
Discussion started by: vikram3.r
3 Replies

7. Shell Programming and Scripting

Formatting isql output to horizontal format

Hi I am formatting informix isql output(vertical) to horizontal format. Suppose I have the following content in the flat file from isql output - item_nbr 0 usfn_label Subscriber Class usfn_name SBCLASS usfn_value bl5 item_nbr 1 usfn_label Switch Name usfn_name switchName... (2 Replies)
Discussion started by: nsinha
2 Replies

8. Shell Programming and Scripting

isql output

hi all i m running following code # set up environment . /u/pimms/pimms_global.ksh echo "Get record from database" #echo ${PIMMS_ID} #echo ${PIMMS_PWD} #echo "1" isql -U${PIMMD_ID} -P${PIMMS_PWD} -S$SRV << eof > /sybase/applications/pimms/bin/automate1.txt use pimms ... (6 Replies)
Discussion started by: d_swapneel14
6 Replies

9. Shell Programming and Scripting

ksh + isql => output cut at 2 GB

Using a ksh script, I'm dumping the data from our sybase database into an output file. This output file is for what ever reason cut at 2GB. There is enough space on the unix machine and as there is no error message is received I have no clue to start looking for a solution. #!... (1 Reply)
Discussion started by: bereman
1 Replies

10. 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
Login or Register to Ask a Question