Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    8

    Unanswered: Select statement surpress no matches

    Hi,

    Is there a way to not output anything if no record is found while doing a select statement? I'm not familiar with db2 at all.

    I'm trying to query a db2 db for any failed jobs and output the result to a file but I don't want any file to be created if nothing has been found.

    Code:
    db2 "select id from aiw.jobs where type='Job' and state_name='Error'"
    ID
    --------------------------------

    0 record(s) selected.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Use the -x command line option to suppress header/trailer output. However, if you redirect the query output to a file, a zero-length file will be created by the shell anyway.

    You may want to check the return code instead -- it will be set to 1 if no rows are returned.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    Thanks for that.. Just what I need.. I can do an if -s for the rest of what I want.

  4. #4
    Join Date
    Jul 2011
    Location
    USA
    Posts
    80
    >> run your select query then run following command

    if [ "$?" = "1" ]; then echo "No row found"; else echo "Row found" ; fi

    run any command, if your command will return 1 then it means no row found from select statement.

Posting Permissions

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