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 > Re: Usage of 'IF EXISTS' statement for DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-03, 09:21
somjit somjit is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
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!
Reply With Quote
  #2 (permalink)  
Old 10-03-03, 14:56
geepee geepee is offline
Registered User
 
Join Date: Jun 2003
Posts: 7
if ( (select count(*) from x where Y = 1) > 0) then
/*
** Then do you logic
*/
end if;
Reply With Quote
  #3 (permalink)  
Old 10-03-03, 15:35
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Hi,
where use this? (in a function, SP, etc or view)

Abel.
Reply With Quote
  #4 (permalink)  
Old 10-05-03, 11:27
geepee geepee is offline
Registered User
 
Join Date: Jun 2003
Posts: 7
Quote:
Originally posted by achiola
Hi,
where use this? (in a function, SP, etc or view)

Abel.
In a stored procedure.
Reply With Quote
  #5 (permalink)  
Old 10-05-03, 13:12
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
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.
Reply With Quote
  #6 (permalink)  
Old 01-15-04, 09:41
speyran speyran is offline
Registered User
 
Join Date: Jan 2004
Posts: 1
A question

Quote:
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.
Reply With Quote
  #7 (permalink)  
Old 01-15-04, 14:13
geepee geepee is offline
Registered User
 
Join Date: Jun 2003
Posts: 7
if ((select count(*) from x where y = 1) > 1) then

else

end if;
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