Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2003
    Posts
    1

    Unanswered: Re: Usage of 'IF EXISTS' statement for DB2

    In Microsoft SQL server I have this statement:

    if exists (select * from emp where id = '100010' ) then
    select * from emp where id = '100010' ;
    else
    print 'Not found';
    end if;

    this obviously checks to see if a record exists for the particular employee before displaying its details.

    what would the DB2 equivalent of this be?

    Thanks from a DB2 newbie!

  2. #2
    Join Date
    Jun 2003
    Posts
    7
    if ( (select count(*) from x where Y = 1) > 0) then
    /*
    ** Then do you logic
    */
    end if;

  3. #3
    Join Date
    May 2002
    Location
    General Deheza, Cba, Arg.
    Posts
    276
    Hi,
    where use this? (in a function, SP, etc or view)

    Abel.

  4. #4
    Join Date
    Jun 2003
    Posts
    7
    Originally posted by achiola
    Hi,
    where use this? (in a function, SP, etc or view)

    Abel.
    In a stored procedure.

  5. #5
    Join Date
    May 2002
    Location
    General Deheza, Cba, Arg.
    Posts
    276
    ok.

    the function "print" no exist in DB2 ( I no know this).
    You can return the value to your program or into a variable (within SP).

    For example:

    select coalesce(pro_codl_id,'NOT FOUND')
    into lPRUEBA
    from db2dwad1.a0_articulos_agd
    where pro_codl_id = '6010010001';


    Tell me more abaut of the objetive.

    Sorry by my English.
    Abel.

  6. #6
    Join Date
    Jan 2004
    Posts
    1

    A question

    Originally posted by geepee
    if ( (select count(*) from x where Y = 1) > 0) then
    /*
    ** Then do you logic
    */
    end if;

    (First, excuse my english...)
    Sorry, but a can't run this statement:
    /*************************************************
    if EXISTS(select 1 from ng_desarrollo.agencias where age_id = 51) then
    Select 1
    elseif
    Select 2
    end if;
    *************************************************/

    Can you tell me why don't run? Or tell me how I must write this statement? Thank you.

  7. #7
    Join Date
    Jun 2003
    Posts
    7
    if ((select count(*) from x where y = 1) > 1) then

    else

    end if;

Posting Permissions

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