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 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

Someone asked the question: INT, BIGINT or UUID/GUID in Oracle, DB2, Derby and HSQLDB?
I want to generate a typed DataSet for both Oracle and DB2 databases from
Using Oracle, is there any way I can execute a query to determine what
Oracle Forms10g provides a tool to convert the Oracle Forms modules, from the binary
Oracle is giving me an error (ORA-00907: missing right parenthesis) when I run this
Oracle has this concept of allowing database users to be identified by the operating
In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN
In Oracle, the number of rows returned in an arbitrary query can be limited
Will Linq work against any database (i.e) MySQL,Sybase,Oracle,DB2?
I'd like ask a question about building applications in .NET that use data from

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.