Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Dynamic SQL in Stored proc not working

Hi,
I am using a stored procedure, that truncates a partitioned table.
And I pass the table name as a parameter to the stored proc. And inside, the stored proc, there is a dynamic sql that truncates the table as per the table name 'in' parameter. The procedure is as follows
DELIMITER $$
CREATE DEFINER=`mpadmin`@`%` PROCEDURE `mysqlproc`(in isactivetoproc int, in tablename varchar(255))
begin
set @sql = concat('alter table ',tablename, ' truncate partition pactive');
if isactivetoproc = 1
then
prepare stmt from @sql;
execute stmt ;
deallocate prepare stmt;
end if;
end$$
DELIMITER ;
I have tested this on mysql and it works fine. But when I call it through talend , it keeps saying there is a syntax error.
However, when I don't use the dynamic sql and use regular SQL, and call through talend it works.
DELIMITER $$
CREATE DEFINER=`mpadmin`@`%` PROCEDURE `mysqlproctest`(in isactivetoproc int, in tablename varchar(255))
begin
alter table farmer truncate partition pactive;
end$$
DELIMITER ;
My intention is to reuse the procedure for all tables. 
Any thoughts on why the first proc is not working
Thanks
Rathi

Labels (2)
5 Replies
Anonymous
Not applicable
Author

Hi,
Did you use component tMysqlSP to call your stored procedure in MySql DB? Could you please show us your setting screenshot?
Have you already checked this KB article about: TalendHelpCenter:Calling a stored procedure or function?
Best regards
Sabrina
Anonymous
Not applicable
Author

Hi Sabrina,
Yes I am using tmysqlsp and mysql db. I have read the article too.
Please find below the screenshot


0683p000009MHOS.png

Regards
Rathi
Anonymous
Not applicable
Author

Hi,
And could you post your tMySqlSP component setting screenshot, please?
Best regards
Sabrina
Anonymous
Not applicable
Author

Hi Sabrina,
PFA the screenshot
0683p000009MH10.png
Anonymous
Not applicable
Author

Hi,
Any update on this?
Thanks
Rathi