Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2013
    Posts
    1

    Unanswered: How do you check if a record exists in a table?

    Hi everyone,
    I'm relatively new to DB2, and I'm wondering if there is any way (e.g. with an IF statement of something of the like that you can query if a certain record exists in a table, and act on it.) For example, search for a book in a library table, and if it doesn't exist, print 'not found'

    Thanks!

  2. #2
    Join Date
    Oct 2008
    Posts
    82
    Better you need to write a shell script for that .. Please provide us the exact query that you have so that will help you more ..

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    For example, search for a book in a library table, ...
    Please show your exact query to search for a book.

    If the query was like
    Code:
    SELECT book_name
     FROM  library_table
     WHERE <some conditions>
    Please try something like the following query to return '*not found*' string, if it doesn't exist.

    Code:
    SELECT COALESCE(book_name , not_found) AS book_name
     FROM  (VALUES '*not found*' ) AS f(not_found)
     LEFT  OUTER JOIN
           library_table
      ON   <some conditions>

Posting Permissions

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