Scenario
- I have a stored procedure written in T-Sql using SQL Server 2005.
- “SEL_ValuesByAssetName”
- It accepts a unique string “AssetName”.
- It returns a table of values.
Question
- Instead of calling the stored procedure multiple times and having to make a database call everytime I do this, I want to create another stored procedure that accepts a list of all the “AssetNames”, and calls the stored procedure “SEL_ValueByAssetName” for each assetname in the list, and then returns the ENTIRE TABLE OF VALUES.
Pseudo Code
foreach(value in @AllAssetsList)
{
@AssetName = value
SEL_ValueByAssetName(@AssetName)
UPDATE #TempTable
}
It will look quite crippled with using Stored Procedures. But can you use Table-Valued Functions instead?
In case of Table-Valued functions it would look something like:
Sample implementation:
First of all, we need to create a Table-Valued Parameter type:
Then, we need a function to get a value of a specific asset:
Next, a function to return a list AssetName, AssetValue for assets list:
Finally, we can test it: