List:General Discussion« Previous MessageNext Message »
From:Brandon Phelps Date:September 21 2011 6:23pm
Subject:Stored Procedure Question
View as plain text  
Hello all,

I would like to create a stored procedure that does the following:

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

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?

Something like this:

@row_id = SELECT id FROM myTable WHERE <blah blah> LIMIT 1;

IF @row_id != nothing THEN
	UPDATE myTable ...
ELSE
	INSERT INTO anotherTable ...
END IF

So if no rows were returned from the select I perform the ELSE block, otherwise I perform
the main IF block.

Thanks!
Thread
Stored Procedure QuestionBrandon Phelps21 Sep
  • Re: Stored Procedure QuestionDerek Downey21 Sep
    • Re: Stored Procedure Question [SOLVED]Brandon Phelps21 Sep