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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:01:28+00:00 2026-06-12T16:01:28+00:00

I have a table that will hold pending data that will update another table

  • 0

I have a table that will hold pending data that will update another table on the same server. This pending table gets it data from another servers stored procedure. Once data is in this pending table, a stored procedure will attempt to insert, update, or delete based on a tinyint column in the pending table.

This pending table will remain empty unless something needs to occur. At the end of the procedure, we delete from this pending table.

An issue arose by way of what happens if the same record that needs to be updated gets inserted twice from the other server while the procedure is running. At the end, both records would be cleared. I’ve attempted to solve this by adding an incremental id onto the pending table but I can’t output the id in the insert:

insert into config.table (col1, col2, col3)
output inserted.col3, pendingId into @table
select p.col1, p.col2, p.col3
from pendingTable p
 left join config.table t on p.col1 = t.col1
where t.col1 is null

I’m getting an error on the pendingId. I plan to use the @table variable to delete from pending to avoid deleting records that were not touched (newly inserted records that were added while procedure was running).

delete p
from pendingTable p
 inner join @table t on p.pendingId = t.pendingId and p.col3 = t.col3
  • 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-12T16:01:30+00:00Added an answer on June 12, 2026 at 4:01 pm

    You need to cache the pending records and delete them after.

    begin tran
    
    select p.pendingid
    into #pendingcache
    from pendingTable p
     left join config.table t on p.col1 = t.col1
    where t.col1 is null
    
    insert into config.table (col1, col2, col3)
    output inserted.col3, pendingId into @table
    select ...
    from #pendingcache
    
    delete p
    from pendingTable p
    inner join #pendingcache c on c.pendingId = p.pendingId
    
    commit
    

    ORIGINAL ANSWER BELOW

    You’re missing inserted before pendingid, i.e. inserted.pendingid. It’s to disambiguate between inserted and deleted.
    The following works.

    Oh, and you’re missing the entire SELECT statement as well, or I’m assuming it’s actually due to creating the “mock” tables for the question?

    create table configtable (col1 int, col2 int, col3 int, pendingid int identity)
    
    create table pendingtable (col1 int, col2 int, col3 int, pendingid int identity)
    insert pendingtable values (1,2,3)
    
    declare @table table (col3 int, pendingid int)
    
    insert into configtable (col1, col2, col3)
    output inserted.col3, inserted.pendingId into @table
    select col1, col2, col3
    from pendingTable p
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that I insert data with following query (from c# code): INSERT
I have a table that have a property named recordsource that will hold the
I have a table that potentially will have high number of inserts per second,
is is possible in postgres to have a trigger on CREATE TABLE that will
I'm working on a project that will have a single table holding lots and
I have a MySQL database, and a particular table in that database will need
I have a page a query that will set a table to 0 or
I have created a GUI that will setup the pivot table. For example, I
I have some code that shows results in a table Right now it will
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName

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.