views:

16

answers:

1

Hi! I'm using VSC++ and MySQL ver.5.2.25 database, I've tested a query In MySQL that is like this:

   select Name from test.virus where Name LIKE 'b' '%' ORDER BY Name;

It works well and return all Names that starts with 'b',I want to use a routine instead of this query, so that I can call the routine from my program. I've tried this:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `StartWith`(NewName VarChar(20))
BEGIN
select NameVirus from test.virus 
where NameVirus LIKE "'+NewName+' '%'" ORDER BY NameVirus;
END

When I Call the routine in MySQL there is no error, but the result is an empty table, I guess that the problem is with type of argument, Which type should be the "NewName" parameter?
Advanced thanks for any reply

A: 

Your like condition in the example query is flawed. It should be 'b%'.

The procedure where clause might need to look like this:

where NameVirus LIKE CONCAT(NewName,'%') order by NameVirus
Fosco
When I call the routine, I use this: "Call test.StartWith("b");" I expected that it works, I don't want to put 'b' in the routine, I want to pars the argument, would you explain more?
rain
Thanks a lot :) , It works.I know that I'm just a starter!
rain