i have a requirement to write a stored procedure that takes 6 potential parameters. I need to do a search on a table that returns rows that match as closely as possible to the search parameters entered.
For example.
Table quotes (status {incomplete, pending, ordered}, date_created date, type {autoGenerated,manual,split} company {PipedPiper, Hooli,Oracle...} ... )
Here is a use case to illustrate what i need to achieve. Lets say a user enters the following search criteria on the front end: they want to get a list of quotes that met the following criteria, or the next best match:
quote status = pending company = PipedPiper type=manual date = Not selected
So, once the stored proc is called it should get the list of quotes that meet that criteria. If, no quotes are in pending then any Piped Piper manual quotes should be returned. Perhaps there are no pending quote for PipedPiper. At that point it should return any manual quotes in the db.
The SP needs to return a cursor and also a flag to confirm what criteria entered is met by the row. please note, it should not return anything against the date flag as the user did not select any date entries for this particular search. For example
if anyone can guide me in how to code this, provide pseudo code, or any guidance is much appreciated. I am poor at SQL so I am struggling to design an SQL statement that can achieve the above.
thanks in advance, Adrian.