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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:13:18+00:00 2026-06-05T05:13:18+00:00

Currently, I’m trying to perform an update in SQL Server (but it could be

  • 0

Currently, I’m trying to perform an update in SQL Server (but it could be any DML statement that supports the output clause), and I’d like to put the output into a local temp table, like so:

update
    dbo.MyTable
set
    MyField = 30
output
    inserted.MyKeyField
into
    #myTempTable
from
    dbo.MyTable as t
where
    f.MyFilteredField = 8 

I know the syntax is correct, as per the documentation for the output clause (emphasis mine):

output_table

Specifies a table that the returned rows are inserted into instead of
being returned to the caller. output_table may be a temporary table.

That said, I’d expect it to work just like it would on the the into clause on a select statement in that it would just create the table.

However, I get the following error:

Invalid object name ‘#myTempTable’.

How can I get the results of the output clause (inserted or deleted) into a temp table?

  • 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-05T05:13:20+00:00Added an answer on June 5, 2026 at 5:13 am

    The output clause will not generate a new table, so you have to generate the table beforehand which matches the structure of what is specified in the output clause, for example:

    select t.MyKeyField into #myTempTable from dbo.MyTable as t where 1 = 0
    

    Note, you don’t have to use the select into syntax above, create table works just as well. In the end, whatever is easiest to create an empty temporary table that matches the fields in your output clause.

    Once the table is created, the “Invalid object name” error will go away and the DML statement will execute without error (assuming there are no other errors).

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

Sidebar

Related Questions

Currently, Enum.Parse supports only the comma as the value separator, so that MemberOne,MemberThree will
Currently playing about with KnockoutJS. Just trying to update an observable array from a
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently, if I want to output a SQL script for a table in my
Currently we use jQuery to add RIA goodness to our apps, but recently we
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently the HashSet<T> constructor that allows you to define your equality comparison yourself is
Currently I'm trying to write my first Python library and I've encountered the following
Currently we're parsing arp request output from the command line. string cmd = arp
currently I'm developing an app for WP7 but came across a little problem with

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.