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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:25:32+00:00 2026-06-01T05:25:32+00:00

I am doing a MERGE statement in SQL Server 2008 R2. What I want

  • 0

I am doing a MERGE statement in SQL Server 2008 R2. What I want to do is to have a more logic inside a NOT MATCHED branch:

WHEN NOT MATCHED THEN
    INSERT (col1, col2, col3) 
    VALUES (SOURCE.col1, SOURCE.col2, SOURCE.col3)
        OUTPUT INSERTED.col1, SOURCE.col4
    INTO @Mapping

    INSERT INTO @newChildren
    (   col1,
    other columns,) 
    SELECT 
    (   TARGET.col1, 
    other columns)
        FROM @input 
        INNER JOIN @Mapping 
        ON @input.col1 = @Mapping.col2

    EXECUTE Children_Create @newChildren;

The idea is to do use INSERT result to form another input to another stored procedure. But it seems control flow is not supported in SQL Server 2008 MERGE. I can’t put BEGIN/END to wrap this code. Any suggestions to overcome this limit?

  • 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-01T05:25:33+00:00Added an answer on June 1, 2026 at 5:25 am

    The INSERT, UPDATE and DELETE keywords being parts of MERGE might have led you into thinking that MERGE is a sort of compound statement. But it is only a complex one. The above-mentioned keywords introduce clauses of MERGE, not separate corresponding statements, however much they may resemble the latter.

    So yes, if not as a separate procedure, yet at least outside MERGE is how your additional inserts must be implemented.

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

Sidebar

Related Questions

I have successfully simulated an Oracle CONNECT BY statement in SQL Server 2008 by
I have looked at various example of the SQL Merge statement.. all of which
I have written a working T-SQL MERGE statement. The premise is that Database A
Does anyone have any experience with doing mail merge from Java on a word
I have a stored procedure that is doing a MERGE. It seems given the
I have tons of data in directory called reports. While doing git merge with
How does gitmergetool works. I have conflicts while doing git merge and now I
I stashed some local changes before doing a complicated merge, did the merge, then
I am doing merge statement in my stored procedure. I need to count the
I have a Merge Join Transform that is doing a Left Outer Join. Can

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.