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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:45:31+00:00 2026-06-09T02:45:31+00:00

I have a feeling I’ve spent too much time on this problem and have

  • 0

I have a feeling I’ve spent too much time on this problem and have been blinded… and hopefully a pair of fresh eyes can help point out a simple error!

This is the MERGE statement I think should work:

Not working:

MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
   AND target.id1 = @id1
   AND target.id2 = @id2
WHEN matched AND NOT (target.iFeeScope = @iFeeScope OR target.nFeeAmount = @nFeeAmount) AND (target.bActive = 1) THEN
  UPDATE SET target.dLastUpdated = @dNow,
             target.dDisabled = @dNow,
             target.bActive = 0;

The problem is in my WHEN matched AND NOT statement: (target.iFeeScope = @iFeeScope OR target.nFeeAmount = @nFeeAmount), and the only way around this I’ve found is to break the statement up into two separate (and almost identical) blocks:

Working (but inefficient):

MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
   AND target.id1 = @id1
   AND target.id2 = @id2
WHEN matched AND NOT (target.iFeeScope = @iFeeScope) AND (target.bActive = 1) THEN
  UPDATE SET target.dLastUpdated = @dNow,
             target.dDisabled = @dNow,
             target.bActive = 0;

MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
   AND target.id1 = @id1
   AND target.id2 = @id2
WHEN matched AND NOT (target.nFeeAmount = @nFeeAmount) AND (target.bActive = 1) THEN
  UPDATE SET target.dLastUpdated = @dNow,
             target.dDisabled = @dNow,
             target.bActive = 0; 

What do I need to change in my original statement to achieve the result of the following two statements?

Thank you all in advance!

  • 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-09T02:45:32+00:00Added an answer on June 9, 2026 at 2:45 am

    Solved it on my own… figured it was an issue with the AND/NOT logic!

    MERGE assignment_tbl AS target
    USING (SELECT 1 s) AS source
    ON target.id = @id
       AND target.id1 = @id1
       AND target.id2 = @id2
       AND target.bActive = 1
    WHEN matched AND (NOT (target.iFeeScope = @iFeeScope)) 
                 OR (NOT (target.nFeeAmount = @nFeeAmount)) THEN
      UPDATE SET target.dLastUpdated = @dNow,
                 target.dDisabled = @dNow,
                 target.bActive = 0; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feeling this is a dumb one, but I've spent some time
I have a feeling this has already been answered, but I don't know the
I have been told that we have a feeling that the database is too
I have a feeling this is a dumb question I should have been able
I have a feeling this will be too wordy, but I'll do my best.
I have a feeling I'm going about this all wrong. But anyway. I have
I have a feeling this XML is not valid, can someone please explain why?
I have the feeling the answer to this question is no but I figured
I have a feeling that this query is pretty easy to construct, I just
I have a feeling this is a stupid question but I can't find the

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.