0

when i call procedure it gives me empty result

   call hussian('prstate','table_1','column1,column2,column3',1)

it run but gives empty result, please help me...

 DELIMITER // 

 CREATE PROCEDURE hussain(IN src_col varchar(20), 
                     IN tblname varchar(100), 
                     IN col_names varchar(100), 
                     IN _leadid int)

 BEGIN
    IF (col_names  = 'column1' AND col_names  = 'column2'  AND col_names = 'column3')
THEN

    SET @sql = CONCAT('insert into ', tblname, '(',col_names,')', ' select ' ,src_col,',','firstname,lastname from tbllead where id = ',_leadid); 
    PREPARE s1 from @sql;
     EXECUTE s1;
    DEALLOCATE PREPARE s1;
 END IF;
  END //
  DELIMITER ; 

it insert data into table when i romove if condition.....

  • SELECT @sql to see what you have constructed. – Rick James Jan 28 at 5:04
1

Basically

'column1' 'column2' 'column3' is different than 'column1,column2,column3'

So, you must compare the whole string:

 BEGIN
IF (col_names  = 'column1,column2,column3')
THEN
.
.
.

If you want to compare each variable separately, then you must pass them separate in your procedure call:

Call:

call hussian('prstate','table_1','column1','column2','column3',1)

Procedure:

CREATE PROCEDURE hussain(IN src_col varchar(20), 
                         IN tblname varchar(100), 
                         IN col_names1 varchar(100), 
                         IN col_names2 varchar(100), 
                         IN col_names3 varchar(100), 
                         IN _leadid int)
  • thanks a lot it is working..... – tajamul hussain Jan 24 at 15:48
  • @tajamulhussain Mark the answer as a solution in such case. – Akina Jan 24 at 18:46
  • @tajamulhussain please mark the answer as the solution for your question. – Jesus Uzcanga Jan 27 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.