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(...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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%') |
|
|||
|
> 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 ; |
|
|||
|
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! |