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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:15:24+00:00 2026-06-12T06:15:24+00:00

My first attempt at a MERGE run is not throughing any errors but it

  • 0

My first attempt at a MERGE run is not throughing any errors but it is not merging the data like I want. Can anyone tell me what I am doing wrong? The point is to compair #Temp and #tblCollectionGameList and update #tblCollectionGameList so that it contains only the items inside #Temp (inserting missing items into tblCollecitonGameList and deleteing items from tblColletionGameList that are no longer in #Temp)

    CREATE TABLE #Temp
(
    CollectionID smallint NOT NULL,
    IncludedSectionID smallint NOT NULL
)

INSERT INTO #Temp (CollectionID, IncludedSectionID) VALUES(0, 0);
INSERT INTO #Temp (CollectionID, IncludedSectionID) VALUES(0, 1);

SELECT * FROM #Temp;

CREATE TABLE #tblCollectionGameList
(
    ID smallint IDENTITY(0,1) NOT NULL,
    CollectionID smallint NOT NULL,
    IncludedSectionID smallint
)

INSERT INTO #tblCollectionGameList (CollectionID, IncludedSectionID) VALUES(0,0);
INSERT INTO #tblCollectionGameList (CollectionID, INcludedSectionID) VALUES(0,2);

SELECT * FROM #tblCollectionGameList;

BEGIN TRAN

MERGE #tblCollectionGameList AS t
USING #Temp AS s
ON (t.CollectionID = s.CollectionID)
WHEN NOT MATCHED BY TARGET
    THEN
        INSERT(CollectionID, IncludedSectionID) VALUES (s.CollectionID, s.IncludedSectionID)
WHEN NOT MATCHED BY SOURCE
    THEN
        DELETE;

SELECT * FROM #tblCollectionGameList;

ROLLBACK TRAN

DROP TABLE #Temp;
DROP TABLE #tblCollectionGameList;
  • 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-12T06:15:25+00:00Added an answer on June 12, 2026 at 6:15 am

    Your problem is that you’re joining on a non-unique column.

    Everything has CollectionID = 1 and so everything matches – there are no rows that meet the NOT MATCHED BY TARGET criteria, and there are no rows that meet the NOT MATCHED BY SOURCE criteria.

    Instead try making the CollectionID unique within a table.

    INSERT INTO #Temp (CollectionID, IncludedSectionID) VALUES(0, 0);
    INSERT INTO #Temp (CollectionID, IncludedSectionID) VALUES(1, 1);
    
    INSERT INTO #tblCollectionGameList (CollectionID, IncludedSectionID) VALUES(0,0);
    INSERT INTO #tblCollectionGameList (CollectionID, INcludedSectionID) VALUES(2,2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider my first attempt, a simple type in F# like the following: type Test()
Here's my simple first attempt at a python extension using boost. Can someone help
This is my lame first attempt. I would like to get a count of
This is my very first attempt at generating images on the fly. I want
This is my first attempt at a plugin but I think I'm missing the
This is my first attempt at CGI (I know some Perl) but i'm falling
It is my first attempt to use pyparsing and I'd like to ask how
First attempt It's difficult to make this question pithy, but to provide a minimal
First attempt to use this cool site - after searching for 2 hours: So
First day and first attempt at using Scala - so go easy on me!

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.