Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    16

    Unanswered: 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

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    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
    Last edited by sathyaram_s; 04-14-04 at 18:32.
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: unix script passing sql value

    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"

  4. #4
    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


    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •