If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > unix script passing sql value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-04, 16:54
tylerr tylerr is offline
Registered User
 
Join Date: Mar 2004
Posts: 16
unix script passing sql value

Hi, I am running DB2 UDB 7.2. I need to write a unix .ksh script that logs into db2, selects the minimum and maximum values from a certain database column, then logs out of db2 and passes this value as a command line argument when executing another program.

The min and max values will need to have a dash in between (something like this: 1000-5000)

Anyone have opinions on how to do this? I'm a little unsure if maybe I should write the value to a file, or if i can do it on the fly, and if a stored proc needs to come into play.

Let me know what you think.
Thanks
Reply With Quote
  #2 (permalink)  
Old 04-14-04, 17:20
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: unix script passing sql value

Are you expecting something like this :

#!/bin/ksh
set -x
db2 "connect to sample"
db2 -x select min\(salary\),max\(salary\) from employee | read minsal maxsal
b.ksh $minsal"-"$maxsal

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.

Last edited by sathyaram_s; 04-14-04 at 17:32.
Reply With Quote
  #3 (permalink)  
Old 04-14-04, 17:27
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: unix script passing sql value

Quote:
Originally posted by tylerr
Hi, I am running DB2 UDB 7.2. I need to write a unix .ksh script that logs into db2, selects the minimum and maximum values from a certain database column, then logs out of db2 and passes this value as a command line argument when executing another program.

The min and max values will need to have a dash in between (something like this: 1000-5000)

Anyone have opinions on how to do this? I'm a little unsure if maybe I should write the value to a file, or if i can do it on the fly, and if a stored proc needs to come into play.

Let me know what you think.
Thanks
Code:
db2 -x "SELECT RTRIM(CHAR(MIN(COLUMN))) || '-' || LTRIM(CHAR(MAX(COLUMN))) FROM TABLE"
Reply With Quote
  #4 (permalink)  
Old 04-14-04, 17:38
tylerr tylerr is offline
Registered User
 
Join Date: Mar 2004
Posts: 16
Re: unix script passing sql value

Guys, thanks for your help. Sathyaram, thats pretty much right on. I just didn't know how to save the min and max salaries and pass them on. Your post cleared this up. Thanks


Quote:
Originally posted by sathyaram_s
Are you expecting something like this :

#!/bin/ksh
set -x
db2 "connect to sample"
db2 -x select min\(salary\),max\(salary\) from employee | read minsal maxsal
b.ksh $minsal"-"$maxsal

Cheers
Sathyaram
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On