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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:40:51+00:00 2026-05-22T18:40:51+00:00

With Oracle (or DB2, HSQLDB), I can express things like this: MERGE INTO [target_table]

  • 0

With Oracle (or DB2, HSQLDB), I can express things like this:

MERGE INTO [target_table]
USING (SELECT 1 FROM dual)
ON [target_table.id = 5]
WHEN MATCHED THEN UPDATE ...
WHEN NOT MATCHED THEN INSERT ...

This just checks if there is already a record with id = 5 in target_table. If there is, then the record is update, if there isn’t then it is inserted. This is roughly the same as MySQL’s more concise

INSERT INTO [target_table] ...
ON DUPLICATE KEY UPDATE ...

How can I do that in SQL Server? According to the documentation, the [table_source] needs to be any of these:

<table_source> ::= 
{
  table_or_view_name [ [ AS ] table_alias ] [ <tablesample_clause> ] 
        [ WITH ( table_hint [ [ , ]...n ] ) ] 
  | rowset_function [ [ AS ] table_alias ] 
        [ ( bulk_column_alias [ ,...n ] ) ] 
  | user_defined_function [ [ AS ] table_alias ]
  | OPENXML <openxml_clause> 
  | derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ] 
  | <joined_table> 
  | <pivoted_table> 
  | <unpivoted_table>
}

http://msdn.microsoft.com/de-de/library/bb510625.aspx

Obviously, SQL Server does not have a DUAL table, but neither is a SELECT statement allowed. What can I put as [table_source] ?

N.B: I found out that I can create a dummy view

CREATE VIEW dummy (one) AS SELECT 1;

and supply that as the [table_source]. But I would like to omit DDL statements just to be able to execute this MERGE statement

  • 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-05-22T18:40:51+00:00Added an answer on May 22, 2026 at 6:40 pm

    See MERGE — look at the example “C. Using MERGE to perform UPDATE and INSERT operations on a target table by using a derived source table” which uses VALUES (aka Table Value Constructor):

    MERGE INTO Target
    USING (VALUES (1))
           AS Source (Number)
    ...
    

    Happy coding.

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

Sidebar

Related Questions

Can SQL Server or db2 do entire database exports like oracle (using exp command)?
Using Oracle, how can I find index names and creation dates from systables/information_schema? How
I want to access oracle tables in DB2(something like DBlink from DB2 to oracle).Any
Someone asked the question: INT, BIGINT or UUID/GUID in Oracle, DB2, Derby and HSQLDB?
In oracle database, command host can be used to run bash command from database
On Oracle 10g we need to insert records from a view into a table
I'm using cx_Oracle to select rows from one database and then insert those rows
I'm trying to display a DATE field fetched from a DB2 instance. In Oracle
Oracle SQL can do hierarchical queries since v2, using their proprietary CONNECT BY syntax.
I've got experience with MySQL, DB2, and Oracle, but aside from writing a few

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.