Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 980899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:27:33+00:00 2026-05-16T04:27:33+00:00

Scenario I have a stored procedure written in T-Sql using SQL Server 2005. SEL_ValuesByAssetName

  • 0

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
}

How would I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:27:33+00:00Added an answer on May 16, 2026 at 4:27 am

    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:

    SELECT al.Value AS AssetName, av.* FROM @AllAssetsList AS al
        CROSS APPLY SEL_ValuesByAssetName(al.Value) AS av
    

    Sample implementation:

    First of all, we need to create a Table-Valued Parameter type:

    CREATE TYPE [dbo].[tvpStringTable] AS TABLE(Value varchar(max) NOT NULL)
    

    Then, we need a function to get a value of a specific asset:

    CREATE FUNCTION [dbo].[tvfGetAssetValue] 
    (   
        @assetName varchar(max)
    )
    RETURNS TABLE 
    AS
    RETURN 
    (
        -- Add the SELECT statement with parameter references here
        SELECT 0 AS AssetValue
        UNION
        SELECT 5 AS AssetValue
        UNION
        SELECT 7 AS AssetValue
    )
    

    Next, a function to return a list AssetName, AssetValue for assets list:

    CREATE FUNCTION [dbo].[tvfGetAllAssets] 
    (   
        @assetsList tvpStringTable READONLY
    )
    RETURNS TABLE 
    AS
    RETURN 
    (
        -- Add the SELECT statement with parameter references here
        SELECT al.Value AS AssetName, av.AssetValue FROM @assetsList al
            CROSS APPLY tvfGetAssetValue(al.Value) AS av
    )
    

    Finally, we can test it:

    DECLARE @names tvpStringTable
    INSERT INTO @names VALUES ('name1'), ('name2'), ('name3')
    
    SELECT * FROM [Test].[dbo].[tvfGetAllAssets] (@names)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008. I have an interesting scenario where a stored procedure
Imagine the following scenario: I am using SQL Server 2005. I have a transaction
Scenario I have a stored procedure written in T-Sql that I use to insert
Scenario :- I have to call MYSQL stored procedure from PHP and do some
It looks like #temptables created using dynamic SQL via the EXECUTE string method have
I have two servers, the first one with SQL Server 2005 and the second
Here's my scenario: Let's say I have a stored procedure in which I need
We have scenario: SQL Server 2008 we have replication on the db we have
I have imported a stored procedure that returns a dataset into my Entity Framework.
I have a strange, sporadic issue. I have stored procedure that returns back 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.