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

  • SEARCH
  • Home
  • 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 7635733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:30:02+00:00 2026-05-31T07:30:02+00:00

Given the following table variable, which contains let’s say some 10K records: DECLARE @SomeTable

  • 0

Given the following table variable, which contains let’s say some 10K records:

DECLARE @SomeTable TABLE
(
    ID int IDENTITY (1, 1) PRIMARY KEY NOT NULL,
    Name varchar(100),
    CustomerMailingAddress1 varchar(100),
    CustomerMailingAddress2 varchar(100),
    CustomerMailingAddress3 varchar(100),
    CustomerMailingAddress4 varchar(100),
    ContactInfo1 nvarchar(256),
    ContactInfo2 nvarchar(256)
)

Currently the table variable gets updated within a sproc as follows:

UPDATE st
SET
    ContactInfo1 = ci.ContactInfo1,
    ContactInfo2 = ci.ContactInfo2
FROM @SomeTable st, dbo.ContactInfoFunc() AS ci

The table function dbo.ContactInfoFunc() simply retrieves the MAX record according to primary key of a table with a single record (it’s company contact info which will seldom if ever change).

Performance-wise is the above update more expensive? In other words, would there be any advantage to rewriting the update to eliminate the join to the table function output as follows:

DECLARE @ContactInfo1 nvarchar(256), @ContactInfo2 nvarchar(256)

SELECT @ContactInfo1 = ContactInfo1, @ContactInfo2 = ContactInfo2
FROM dbo.ContactInfoFunc()

UPDATE st
SET
    ContactInfo1 = @ContactInfo1,
    ContactInfo2 = @ContactInfo2
FROM @SomeTable st

Or is it a toss-up? Would the query optimizer be smart enough to cache the output of the table function or would it spin its wheels executing the function for each row being updated?

  • 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-31T07:30:03+00:00Added an answer on May 31, 2026 at 7:30 am

    Not sure what else you’re doing with the table variable, but why do you need to update it at all? Let’s assume you just end up doing a SELECT from it at the end. So your code could easily be:

    DECLARE @ContactInfo1 nvarchar(256), @ContactInfo2 nvarchar(256)
    
    SELECT @ContactInfo1 = ContactInfo1, @ContactInfo2 = ContactInfo2
    FROM dbo.ContactInfoFunc();
    
    ...
    
    SELECT 
        ID,
        Name,
        CustomerMailingAddress1,
        CustomerMailingAddress2,
        CustomerMailingAddress3,
        CustomerMailingAddress4,
        ContactInfo1 = @ContactInfo1, -- these don't need to be a fixture in the table to
        ContactInfo2 = @ContactInfo2  -- be involved in the resultset or other activity...
    FROM @SomeTable;
    

    Now, my answer would be different if the function actually took parameters, and the output depended on those parameters. Then it might make sense to perform a CROSS APPLY perhaps… but again not to perform an UPDATE, just as a function of the final SELECT…

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

Sidebar

Related Questions

Given the following: declare @a table ( pkid int, value int ) declare @b
Given the following table in SQL Server 2005: ID Col1 Col2 Col3 -- ----
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Given the following html table and script shown below I am having a problem
Given an Oracle table created using the following: CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME
Given the one-table design given below how would the following best be queried The
Given a table (id, col1, col2), does it make sense to create the following
I have a necessity to sort a given HTML table of the following structure,
Given following snippet (MS SQL): DECLARE UpdateList CURSOR FOR SELECT MyColumn FROM MyTable OPEN
We have a table of transactions which is structured like the following : TranxID

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.