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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:52:57+00:00 2026-05-26T23:52:57+00:00

This is one annoying issue and I can’t figure out how to solve it.

  • 0

This is one annoying issue and I can’t figure out how to solve it. I’m Using Microsoft SQL Server 2008.

So I have two tables and I need to update both of them. They share a common key, say id. I want to update Table1 with some stuff and then update the Table2 rows which were respectively modified in Table1.

The issue is that I don’t quite know which rows were modified, because I’m picking them randomly with ORDER BY NEWID() so I probably cannot use a JOIN on Table2 in any way. I am trying to save the necessary details which were modified in my query for Table1 and pass them to Table2

This is what I’m trying to do

CREATE TABLE IDS (id int not null, secondid int)

SELECT [Table1].[id], [Table1].[secondid]
INTO IDS
FROM
(
UPDATE [Table1]
SET [secondid]=100
FROM [Table1] t
WHERE t.[id] IN 
    (SELECT TOP 100 PERCENT t.[id] FROM [Table1]
        WHERE (SOME_CONDITION)
        ORDER BY NEWID()
    ) 
)

UPDATE [Table2]
SET some_column=i.secondid
FROM [Table2] JOIN IDS i ON i.id = [Table2].[id]

But I get

Incorrect syntax near the keyword ‘UPDATE’.

So the question is: how can I solve the syntax error or is it a better way to do this?

Note: the query enclosed between the parentheses of the first FROM worked well before this new requirement, so I doubt there’s a problem in there. Or maybe?

EDIT: Changing the second UPDATE as skk suggested still leads to the same error (on exactly the below line which contains UPDATE):

UPDATE [Table2]
SET some_column=i.secondid
FROM [Task] JOIN IDS i on i.[id]=[Table2].[id]
WHERE i.id=some_value
  • 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-26T23:52:58+00:00Added an answer on May 26, 2026 at 11:52 pm

    It’s complaining because you aren’t aliasing the derived table used in the first query, immediately preceding UPDATE [Table2].

    If you add an alias, you’ll get a different error:

    A nested INSERT, UPDATE, DELETE, or MERGE statement must have an OUTPUT clause.

    Which leads back to @Adam Wenger’s answer.


    Not sure I completely understand what you are trying to do, but the following sql will execute (after replacing SOME_CONDITION):

    CREATE TABLE IDS (id int not null, secondid int)
    
    UPDATE t SET [secondid] = 100
    OUTPUT inserted.[id], inserted.[secondid] into [IDS]
    FROM [Table1] t
    WHERE t.[Id] IN
        (
            SELECT TOP 100 PERCENT t.[id] from [Table1]
            WHERE (SOME_CONDITION)
            ORDER BY NEWID()
        )
    
    UPDATE [Table2]
    SET some_column = i.secondid
    FROM [Table2] JOIN IDS i ON i.id = [Table2].[id]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this annoying issue where my android google nexus one can't run my
Can any one help me with this syntax issue with C#? I have no
I'm facing an annoying issue and I can't find out why. I have a
Oh wow is this one annoying me. Using c#, winforms, visual studio 2010 ulti.
I have this very annoying issue, whenever i call a function: void renderGame::renderMovingBlock(movingBlock* blockToRender){
I have a rather annoying cosmetic issue with jQuery. I'm using the $(window).scroll event
I have a real annoying issue with form.is_valid() always returning false on one of
I am using the jQuery plugin Jcrop. I have an issue with one of
this one is not homework, it just the fact that i've been out of
I'm running into a very annoying issue. One of our SPROC is building up

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.