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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:05:38+00:00 2026-06-04T15:05:38+00:00

I have got a T-SQL MERGE command that works fine on my SQL Server

  • 0

I have got a T-SQL MERGE command that works fine on my SQL Server 2008. Unfortunately, the code has to work on a SQL Server 2005 database, too.

What would I have to change, to make the following code runnable in SQL Server 2005?

Thank you for your help.

DECLARE @CNVAL varchar(100) = 'xyz' DECLARE @ATRBT varchar(100) = 'abcde' DECLARE @CON varchar(100) = 'fgh' 
MERGE into CNEXTR as target
USING (VALUES( @CON, @ATRBT, @CNVAL))
     AS source([Name], ATTR, CNVAL)
     ON (target.[Name] = source.[Name])
     AND (target.ATTR = source.ATTR)
WHEN MATCHED THEN 
     UPDATE SET 
         CNVAL = source.CNVAL 
WHEN NOT MATCHED THEN 
     INSERT([Name], ATTR, CNVAL) 
     VALUES(source.[Name], source.ATTR, source.CNVAL);
  • 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-04T15:05:40+00:00Added an answer on June 4, 2026 at 3:05 pm

    Change this to

    BEGIN TRAN
    
       UPDATE CNEXTR
       SET CNVAL = @CNVAL
       WHERE [Name] = @CON AND ATTR = @ATRBT;
    
       IF @@ROWCOUNT = 0
           INSERT CNEXTR ([Name], ATTR, CNVAL)
           VALUES(@CON, @ATRBT, @CNVAL);
    
    COMMIT TRAN
    

    Each statement will be far simpler than the MERGE

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

Sidebar

Related Questions

I have got two tables in SQL Server 2005: USER Table: information about user
I have got hold of a sql server 2008 developer edition and this is
I have got 2 fields in my db(sql server 2008) namely updateDate[Datetime] & calldate[datetime].
I have a column in SQL Server 2005 that stores a simple chunk of
I have got a database of ms-sql server 2005 named mydb, which is being
I have got a field that has been setup to allow for Null, but
I have got the following SQL statement (SQL Server): DECLARE @atr nvarchar(255), @con nvarchar(1000),
I Need to Get BIDS Installed. I Have got VS2010 and Sql Server Developer
I have got a excel sheet which inserts data in to SQL Server, but
I have got a table that is a result of a (My)SQL query. In

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.