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 9133219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:26:54+00:00 2026-06-17T08:26:54+00:00

In SQL Server, I have a CLR integration based table valued function, GetArchiveImages. I

  • 0

In SQL Server, I have a CLR integration based table valued function, GetArchiveImages. I call it something like this:

SELECT ...
FROM Items
CROSS APPLY GetArchiveImages(Items.ID) AS archiveimages
WHERE ...

The issue is that there is overhead for each individual call to the function.

If it could be joined with the whole table at once, the overhead would be quite minor, but since it’s called once for each row, that overhead scales with the number of rows.

I don’t use a stored procedure, because a table returned by a stored procedure can’t be joined with anything (as far as I know).

Is there an efficient way to join tables with the results of a stored procedure or function in bulk, instead of row by row?

  • 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-06-17T08:26:55+00:00Added an answer on June 17, 2026 at 8:26 am

    As the result of GetArchiveImages depends on the Items.ID SQL Server has to call the function for each item, otherwise you wont get correct results.

    The only function that SQL Server can “break up” is a T-SQL Inline Table Valued Function. So if you can rewrite your CLR as a ITVF, you will get better performance.

    In my experience, the overhad of calling a CLR function however is not that big. It is much more likely that you are having problems somewhere else in the query. For example, SQL Server has no idea how many rows will be returned by that function and just assumes it will be one (for each call). That can lead to misinformed decisions in other places during the optimization process.


    UPDATE:

    SQL Server does not allow to keep static non-constant data within a CLR class. There are ways to trick the system, e.g. by creating a static final collection object (you can add and remove items from a static collection), however, I would advise against that for stability reasons.

    In you case It might make sense to create a cache table that is refreshed either automatically with some sort of (database- or file-system-) trigger or on a schedule. Instead of calling the function you can then just join with that table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2005 I have an SQL Function (ftn_GetExampleTable) which returns a table with
In SQL Server 2008 I have a user table like the following: Userid Username
I have table-valued parameters in SQL Server 2008, e.g.: CREATE TYPE UserType AS TABLE
I'm using a CLR table-valued function to SELECT and return the results of a
Does each column of a table in SQL Server have a unique id? I've
Does SQL Server 2008 have a a data-type like MySQL's enum ?
In Microsoft SQL Server: I have seen this question several times, but can't see
It is possible in SQL Server Express have a log of all operations SELECT
[using SQL Server 2005] I have a table full of users, I want to
I have an interface in CLR between SQL Server and the Exchange Web Services

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.