Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one table(EMPLOYEE),in that columns are (Emp_Id, First_Name, Last_Name, Gender, Mobile_No, Email_id, Blood_Group);

In my front end page having 4 text boxes that is emp_id, emp_name, mobile_no, blood_group.
(here search buttion),

Whenever we give id( or) name (or )mbno( or) bloodgroup(or) any combinations then result come with (Emp_Id, First_Name, Last_Name, Gender, Mobile_No, Email_id, Blood_Group)display.

I try some code but result is not coming.code is following
----------------------------
DELIMITER $$
CREATE  PROCEDURE sp_srch(in empid varchar(10), empname varchar(45),mobileno varchar(15),bloodgroup varchar(5))
BEGIN
    declare str varchar(255);
    declare str1 varchar(20);
    declare str2 varchar(20);
    set  str ="select Emp_Id,First_Name,Last_Name,Gender,Mobile_No,Email_id,Blood_Group from Employee where ";
    if(empid!= '') then
       set   str= Concat(str ,"Emp_ID like '%", empid ,"%'and ");
    end if;
    if(empname!='') then
       set   str= Concat(str , "First_Name like '%" , empname ,"%'and ");
    end if;
    if(mobileno!='') then
       set  str= Concat(str , "Mobile_No like '%" , mobileno ,"%'and ");
    end if;
    if(bloodgroup!='') then
       set  str= Concat(str ,"Blood_Group like '" , bloodgroup ,"%' ");
    end if;
    set str1= (SUBSTR(str,-6));
    set str2 = (SUBSTR(str,-4));

    if(str1='where') then
     set str= replace(str,'where','');
      end if;
    if(str2='and') then
      set str= replace(str,' and','');
       end if;
select str;

END $$
DELIMITER ;
Posted
Updated 20-Oct-10 22:06pm
v3
Comments
Dalek Dave 21-Oct-10 4:06am    
Edited for Grammar, Spelling and Readability.

how bout adding exec str near the end somewhere? :P u dnt execute the proc u just string manipulate until end.
 
Share this answer
 
change
select str;

to
exec str;


select str does't execute the query
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900