» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2006, 11:54 AM
scrooge scrooge is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
scrooge is on a distinguished road
Default IF-ELSE in stored proc.

Hi everybody

I've 2 tables tbl1 and tbl2 with same structure

lets say like: id and name as field

i'll send 'name' to stored procedure then it should see if 'name' exists in tbl1 then some statement should be exectued or if tbl2 has this name then some statement shoudl be exectued

example

If (select name from tbl1 where name=name) then

statement....

Else (select name from tbl2 where name=name) then
stament...

tbl1 has priority on tbl2 if name is found in tbl1 then tbl2 should be skipped.

I was unable to do it in stored proc, can someone guide me how to get it fixed?

Thanks a million -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-09-2006, 11:55 AM
pinnacle pinnacle is offline
OSP Starters
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pinnacle is on a distinguished road
Talking

Code:

select 1 as tbl from tbl1 where name='name'
union all
select 2 from tbl2 where name='name'
order by tbl limit 1this will give you one of the following three result sets --

Code:
tbl tbl tbl
--- --- ---
NULL 1 2 now you can do an IF on the result and then you can execute whatever you want

hope that helps -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive stored procedures/functions? Coonor MySQL Forums 1 02-24-2007 09:03 AM
stored procedure creating problem? Wumchi MySQL Forums 1 11-23-2006 04:57 AM
problem with stored procedures?? Vanis MySQL Forums 1 10-23-2006 05:48 AM
installing 5.0 on Windows XP gives problem... Elisabeth MySQL Forums 0 08-01-2006 01:24 PM


All times are GMT. The time now is 12:39 PM.