Use output of Stored Procedure as where condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BHTanna
    New Member
    • Aug 2008
    • 31

    Use output of Stored Procedure as where condition

    I have one stored procedure, which defines where condition based useing Case when...I m storing this Condition in one outpur variable of Store procedure.


    I would like to now use this condition in view or Query...

    Pls guide how to do this or is there any other way of doing the same?

    Also note that, my case when defines entire condition .. It is not only giving criteria... like = or > part..

    It is giving everthing after where...

    Can anyone guide me...

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You can use Prepared statements

    For example:
    [code=mysql]
    /* Call your statement, puting the results in @s */
    CALL CreateWhereClau se(@s);

    /* Construct your query as a string */
    SET @q = CONCAT('SELECT * FROM myTable WHERE ', @s);

    /* Create and execute the query */
    PREPARE stmt FROM @q;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt ;

    [/code]

    Comment

    Working...