LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-18-2012, 02:10 PM   #1
rootaccess
Member
 
Registered: Mar 2012
Posts: 311

Rep: Reputation: Disabled
mysql stored procedure help


Hi. I'm basically trying to create a stored procedure with parameters where I can pass off either 'Y' OR 'N' (but not both at the same time) as parameters to change values in a table.

I have a table called procedures.
In there 4 rows are listed.
If I pass 'Y' as a parameter, it needs to update 2 rows; for mike and tom.
If I pass 'N' as a parameter, it updates the other 2 rows; for dick and harry.

Here is what I have listed and I tried playing with so many different ways and have not succeeded.

Code:
create procedure yn (IN x char(1))
BEGIN
SET x = Y or N;
IF x = Y THEN
UPDATE procedures SET number1 = 3, number2 = 4, number3 = 5 WHERE Name='mike';
UPDATE procedures SET number1 = 3, number2 = 2, number3 = 1 WHERE Name='tom';
END IF;
IF x = N THEN
UPDATE procedures SET number1 = 5, number2 = 6, number3 = 7 WHERE Name='dick';
UPDATE procedures SET number1 = 22, number2 = 33, number3 = 44 WHERE Name='harry';
END IF;
END; //
If someone can please help me, I would appreciate it.

Thanks,
Shawn
 
Old 10-18-2012, 02:18 PM   #2
rootaccess
Member
 
Registered: Mar 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
I figured it out myself. For anyone curious for some odd strange reason, here is the stored procedure as well as how to call it

Code:
create procedure yn (IN x char(1))
BEGIN
IF x = 'Y' THEN
UPDATE procedures SET number1 = 3, number2 = 4, number3 = 5 WHERE Name='mike';
UPDATE procedures SET number1 = 3, number2 = 2, number3 = 1 WHERE Name='tom';
END IF;
IF x = 'N' THEN
UPDATE procedures SET number1 = 5, number2 = 6, number3 = 7 WHERE Name='dick';
UPDATE procedures SET number1 = 22, number2 = 33, number3 = 44 WHERE Name='harry';
END IF;
END; //
Code:
call yn ('Y');
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can bind dlz work with the mysql stored procedure? oranix Linux - Server 1 01-22-2011 06:58 AM
Problem creating Stored Procedure in MySQL Administrator andrewhiggs Linux - Software 1 07-23-2010 03:27 AM
Locking in Stored Procedure dugas Programming 2 03-25-2007 11:40 AM
MySQL Stored Procedure Question?? sehgals Linux - Software 5 01-31-2005 01:54 PM
stored procedure in mysql suchi_s Programming 2 10-01-2004 06:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration