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

The Archive Base Latest Questions

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

I have the table tblCollectionGameList CREATE TABLE dbo.tblCollectionGameList ( ListID smallint IDENTITY(0,1) NOT NULL,

  • 0

I have the table tblCollectionGameList

CREATE TABLE dbo.tblCollectionGameList
(
    ListID smallint IDENTITY(0,1) NOT NULL,
    CollectionID smallint NOT NULL,
    IncludedSectionID smallint NOT NULL,
    CONSTRAINT PK_CollectionGameList_ListID PRIMARY KEY CLUSTERED (ListID ASC),
    CONSTRAINT FK_CollectionGameList_SectionInfo FOREIGN KEY (CollectionID) REFERENCES dbo.tblSectionInfo (SectionID),
    CONSTRAINT FK_CollectionGameList_SectionInfo2 FOREIGN KEY (IncludedSectionID) REFERENCES dbo.tblSectionInfo (SectionID)
)

which I run the following MERGE command on after passing an XML set of values to from my website

SELECT 
   CAST(colx.query('data(CollectionID) ') AS varchar) AS CollectionID,
   CAST(colx.query('data(IncludedSectionID) ') AS varchar) AS IncludedSectionID
INTO #TEMPtblCollectionGameList
FROM @XMLTable.nodes('DocumentElement/XMLTable') AS Tabx(Colx)

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

which is not working right. If I have an existing set of data in my table:

ListID  CollectionID    IncludedSectionID
34      86              0
35      86              1

and I try to place new data from my web page for a collection with a different CollecitonID it is removing the old data and placing the new data in:

ListID  CollectionID    IncludedSectionID
38      92              10
39      92              11

what is wrong with my MERGE code that is making it affect items outside the CollectionID that the webpage is passing for an update?

  • 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-12T15:18:17+00:00Added an answer on June 12, 2026 at 3:18 pm

    The solution was to add the following:

    WITH tblCGL AS
    (
        SELECT ListID, CollectionID, IncludedSectionID
        FROM dbo.tblCollectionGameList AS CGL
        WHERE EXISTS
        (
            SELECT CollectionID, IncludedSectionID
            FROM #TEMPtblCollectionGameList AS TempCGL
            WHERE CGL.CollectionID = TempCGL.CollectionID
        )
    )
    

    this was gather by the help at the guys from SQLteam.com.

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

Sidebar

Related Questions

I have table named A with column B defined int not null Primary Key
I have table as below personalInfo CREATE TABLE personalInfo(userid BIGINT AUTO_INCREMENT PRIMARY KEY) patentInfo
i have table and i tried to add `id` int(11) NOT NULL auto_increment, to
I have table with following details Table name EMPLOYEE and columns EMPID (PK smallint
I have table structures that include a composite primary key of id & revision
I have table field defined as like this approved_at DATETIME YEAR TO SECOND NOT
I have table, and I want check/uncheckcheck box not only by clicking on checkbox,
I have table in mysql with MyISAM storage engine. I want to create partition
I have table with around 70 000 rows. There is 6000 rows that i
I have table in which I am inserting rows for employee but next time

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.