Stored Proc Question

This is a discussion on Stored Proc Question within the MySQL Database forums, part of the Database Forums category; I have a stored Proc: DELIMITER $$ DROP PROCEDURE IF EXISTS `ATF`.`spSearch` $$ CREATE DEFINER=`root`@`%` PROCEDURE `spSearch`(IN sSearch VARCHAR(...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-19-2007
HarveyCA@gmail.com
 
Posts: n/a
Default Stored Proc Question

I have a stored Proc:

DELIMITER $$

DROP PROCEDURE IF EXISTS `ATF`.`spSearch` $$
CREATE DEFINER=`root`@`%` PROCEDURE `spSearch`(IN sSearch
VARCHAR(20),IN sSearchCrit varchar(45))
BEGIN
SET @a = sSearch;
SET @b = sSearchCrit;
SELECT * FROM Portage_Insurance WHERE @a LIKE @b ORDER BY First_name
ASC;
END $$

DELIMITER ;

and when I call it like:

CALL spSearch(Last_name,'%Some Name%')

I get an error saying "Unknown column 'Last_name' in 'field list'";
however I am certain that Last_name is a column in the table as well
as the correct case. What am I missing?

Reply With Quote
  #2 (permalink)  
Old 07-19-2007
lark
 
Posts: n/a
Default Re: Stored Proc Question

HarveyCA@gmail.com wrote:
> I have a stored Proc:
>
> DELIMITER $$
>
> DROP PROCEDURE IF EXISTS `ATF`.`spSearch` $$
> CREATE DEFINER=`root`@`%` PROCEDURE `spSearch`(IN sSearch
> VARCHAR(20),IN sSearchCrit varchar(45))
> BEGIN
> SET @a = sSearch;
> SET @b = sSearchCrit;
> SELECT * FROM Portage_Insurance WHERE @a LIKE @b ORDER BY First_name
> ASC;
> END $$
>
> DELIMITER ;
>
> and when I call it like:
>
> CALL spSearch(Last_name,'%Some Name%')
>
> I get an error saying "Unknown column 'Last_name' in 'field list'";
> however I am certain that Last_name is a column in the table as well
> as the correct case. What am I missing?
>

how about this:

call spSearch('Last_name', '%Some Name%')

Reply With Quote
  #3 (permalink)  
Old 07-20-2007
HarveyCA@gmail.com
 
Posts: n/a
Default Re: Stored Proc Question


> how about this:
>
> call spSearch('Last_name', '%Some Name%')- Hide quoted text -
>
> - Show quoted text -


Here is what ended up working:

DELIMITER $$

DROP PROCEDURE IF EXISTS `ATF`.`spSearch` $$
CREATE DEFINER=`root`@`%` PROCEDURE `spSearch`(IN sSearch VARCHAR(20),
IN sSearchCrit VARCHAR(45))
BEGIN
/*SET @query = CONCAT('SELECT * FROM Portage_Insurance WHERE ',
sSearch, ' LIKE ''%', sSearchCrit, '%''');*/
SET @query = CONCAT('SELECT * FROM Portage_Insurance WHERE ',
sSearch, ' LIKE ''', sSearchCrit, '%''');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END $$

DELIMITER ;


Reply With Quote
  #4 (permalink)  
Old 07-20-2007
lark
 
Posts: n/a
Default Re: Stored Proc Question

HarveyCA@gmail.com wrote:
>> how about this:
>>
>> call spSearch('Last_name', '%Some Name%')- Hide quoted text -
>>
>> - Show quoted text -

>
> Here is what ended up working:
>
> DELIMITER $$
>
> DROP PROCEDURE IF EXISTS `ATF`.`spSearch` $$
> CREATE DEFINER=`root`@`%` PROCEDURE `spSearch`(IN sSearch VARCHAR(20),
> IN sSearchCrit VARCHAR(45))
> BEGIN
> /*SET @query = CONCAT('SELECT * FROM Portage_Insurance WHERE ',
> sSearch, ' LIKE ''%', sSearchCrit, '%''');*/
> SET @query = CONCAT('SELECT * FROM Portage_Insurance WHERE ',
> sSearch, ' LIKE ''', sSearchCrit, '%''');
> PREPARE stmt FROM @query;
> EXECUTE stmt;
> DEALLOCATE PREPARE stmt;
> END $$
>
> DELIMITER ;
>
>

nice!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



All times are GMT +1. The time now is 04:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0