Operating System - HP-UX
1753278 Members
5640 Online
108792 Solutions
New Discussion юеВ

Re: Using EXEC with INSERT INTO

 
prandip
Occasional Contributor

Using EXEC with INSERT INTO

I am having problems inserting into a table from tuples returned through exec. Here's an example of the code:

INSERT INTO EXEC

e.g. INSERT INTO #temptbl EXEC tempproc

I get the error:
Incorrect syntax near the keyword EXEC

Kindly advice
6 REPLIES 6
Yogeeraj_1
Honored Contributor

Re: Using EXEC with INSERT INTO

hi,

the correct syntax would be:

insert into select ...

hope this helps!

yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
prandip
Occasional Contributor

Re: Using EXEC with INSERT INTO

Hi Yogeeraj,
Thanks again but i am aware of that. I want to use values returned from a stored procedure, hence my problem. Again SQL Server allows using EXEC after INSERT INTO. Sybase is again giving me a no-no. Kindly advice on a work around on the syntax if there exists one.

Revert

Prandip
Remigiusz_1
Frequent Advisor

Re: Using EXEC with INSERT INTO

HI!

If stored procedyre return one value:

declare @return int
exec @return =
insert into values(@return)

when stored procedure return more than one values you must define procedure to set values of its parameters

delcare @ret1 int, @ret2 int
exec @ret1 output, @ret2 output
insert into values (@ret1, @ret2)

:-) ..
on MS SQL Server should work
... sory my english !!
Remigiusz
Remigiusz_1
Frequent Advisor

Re: Using EXEC with INSERT INTO

HI!

If stored procedyre return one value:

declare @return int
exec @return =
insert into values(@return)

when stored procedure return more than one values you must define procedure to set values of its parameters

delcare @ret1 int, @ret2 int
exec @ret1 output, @ret2 output
insert into values (@ret1, @ret2)

:-) ..
on MS SQL Server should work
... sory my english !!
Remigiusz
Remigiusz_1
Frequent Advisor

Re: Using EXEC with INSERT INTO

HI!

If stored procedyre return one value:

declare @return int
exec @return =
insert into values(@return)

when stored procedure return more than one values you must define procedure to set values of its parameters

delcare @ret1 int, @ret2 int
exec @ret1 output, @ret2 output
insert into values (@ret1, @ret2)

:-) ..
on MS SQL Server should work
... sory my english !!
Remigiusz
prandip
Occasional Contributor

Re: Using EXEC with INSERT INTO

Thanks mate!! No problem on english i assure you. I guess this will suffice for me now. Thanks again!!