From: Derek Downey Date: September 21 2011 6:34pm Subject: Re: Stored Procedure Question List-Archive: http://lists.mysql.com/mysql/225794 Message-Id: <6E0218E8-0704-4C05-96EA-85F083AAB27A@orange-pants.com> MIME-Version: 1.0 (Apple Message framework v1244.3) Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable SELECT id INTO @row_id FROM myTable WHERE LIMIT 1; Source=20 http://dev.mysql.com/doc/refman/5.5/en/select-into-statement.html On Sep 21, 2011, at 2:23 PM, Brandon Phelps wrote: > Hello all, >=20 > I would like to create a stored procedure that does the following: >=20 > 1. Accepts 4 values as parameters > 2. SELECTS 1 record (LIMIT 1) from a table where the 4 parameters = match fields in that table > a. If a record was returned then UPDATE the table > b. If a record was not returned then INSERT into a different = table >=20 > My main question here is how can I execute a SELECT id FROM ... LIMIT = 1 statement within a stored procedure then use the returned id field = later in the procedure? >=20 > Something like this: >=20 > @row_id =3D SELECT id FROM myTable WHERE LIMIT 1; >=20 > IF @row_id !=3D nothing THEN > UPDATE myTable ... > ELSE > INSERT INTO anotherTable ... > END IF >=20 > So if no rows were returned from the select I perform the ELSE block, = otherwise I perform the main IF block. >=20 > Thanks! >=20 > --=20 > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: = http://lists.mysql.com/mysql?unsub=3Dderek@stripped >=20