1

i want to store data returned from stored procedure to a table. i have tried this.

insert into table1 call sp_test();

but it fails.

how do i do this ?

Chetan Patel
  • 183
  • 2
  • 10
  • possible duplicate of [MySQL How to INSERT INTO \[temp table\] FROM \[Stored Procedure\]](http://stackoverflow.com/questions/687102/mysql-how-to-insert-into-temp-table-from-stored-procedure) – juergen d Jun 28 '12 at 06:42

3 Answers3

1

Try this

call sp_test(@var)    
insert into table1 (select @var);

And in procedure there shoud be out variable in arguments

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103
  • This is the beginning of the right answer: you can't redirect or use the 'output' of the stored procedures. The answer would be better completed with how the inside of the stored procedure should look like. – snooze92 Dec 10 '13 at 18:10
0

If it returns data, it is a stored function, not a stored procedure. In that case you don't use CALL but simply use it in a INSERT … SELECT statement, like this:

INSERT INTO table1 SELECT sp_test()
MvG
  • 57,380
  • 22
  • 148
  • 276
  • Then it has to have parameters to return anything through them, and your example didn't indicate any. WIthout those, the result of your queries inside the SP will be lost once the procedure returns. – MvG Jun 28 '12 at 07:00
-1

for function use select

insert into table1 select sp_test();

how to insert into...stored-procedure

Community
  • 1
  • 1