Starting with sql server 2008, you can use table valued parameters to pass a table structured data in a single call to a stored procedure.
However, Not every client supports this. It's easy to use with .Net, but I doubt it's possible with VBScript, for instance.
In order to use a table valued parameter you must first create a user defined table type:
CREATE TYPE UDT_Portfolio As Table
(
Portfolio_Id int,
Portfolio_Name varchar(10),
.....
)
in your case, since you want to pass 2 tables, you need 2 types:
CREATE TYPE UDT_Trades As Table
(
Trade_Id int,
Trade_Portfolio_Id int,
Trade_Name varchar(10),
....
)
Now, to use them in a stored procedure is very easy:
CREATE PROCEDURE stp_InsertPortfoliosAndTrades
(
@Portfolio UDT_Portfolio readonly, -- Note: Readonly is a must
@Trade UDT_Trades readonly
)
AS
-- stored procedure logic here
Note #1:: Table valued parameters are readonly. meaning you can't use update, insert or delete statements on them.
However, you can declare a table valued variable inside a stored procedure and use insert, update, and deletes on that.
Note #2: If your portfolio id is an identity column, then when inserting the data to the portfolio table you will need to use an output
clause to get the new id values.