How a function/procedure can be called inside a insert statement without command parameters. e.g.
Insert into myTable (....) values (1,2,mySP_or_mySDF, 3,4)
How a function/procedure can be called inside a insert statement without command parameters. e.g.
Insert into myTable (....) values (1,2,mySP_or_mySDF, 3,4)
You can also use INSERT INTO... SELECT
INSERT INTO myTable (col1, col2, col3....)
SELECT 1, 2, mySP_or_mySDF(), 3, 4
If you want to INSERT
data from a stored procedure, then you will need to create a temp table and insert the result into the temp table first, then you can use the result to insert into the final table.
You cannot call a stored procedure within a SELECT/UPDATE/INSERT statement, with the exception of the statement SQL:
insert into <whatever>
exec <some sql statement here>;
(and related constructs).
Stored procedures do not really return values. Well, they do return an integer. So, you could do:
declare @retval int;
exec @retval = mysp;
insert into myTable(col1, col2, col3, col4)
select 1, 2, @retval, 3, 4
You could have the stored procedure "return" all 4 values, by including the following statement in the sp body:
select 1, 2, <whatever>, 3, 4
and then doing insert into myTable(col1, col2, col3, col4) exec mysp;