Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 8th, 2008, 11:03 AM
Newbie
 
Join Date: Aug 2008
Posts: 31
Default 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
Reply
  #2  
Old August 16th, 2008, 07:21 AM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,783
Default

Hi.

You can use Prepared statements

For example:
Expand|Select|Wrap|Line Numbers
  1. /* Call your statement, puting the results in @s */
  2. CALL CreateWhereClause(@s);
  3.  
  4. /* Construct your query as a string */
  5. SET @q = CONCAT('SELECT * FROM myTable WHERE ', @s);
  6.  
  7. /* Create and execute the query */
  8. PREPARE stmt FROM @q;
  9. EXECUTE stmt;
  10. DEALLOCATE PREPARE stmt ;
  11.  
  12.  
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles