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.....

asked Jan 24, 2020 at 15:16
1
  • SELECT @sql to see what you have constructed. Commented Jan 28, 2020 at 5:04

1 Answer 1

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)
answered Jan 24, 2020 at 15:33
2
  • @tajamulhussain Mark the answer as a solution in such case. Commented Jan 24, 2020 at 18:46
  • @tajamulhussain please mark the answer as the solution for your question. Commented Jan 27, 2020 at 18:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.