Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

MERGE INTO Example - SQL Server

RSS
Modified on Thu, Jul 17, 2014, 2:05 PM by Administrator Categorized as SQL Server
MERGE INTO SecurityQuestion AS Target 
USING (VALUES 
       (1, N'What is your mother''s maiden name?'),
       (2, N'What is the name of the street you grew up on?'),
       (3, N'What is the name of your first pet?'),
       (4, N'What was your favorite food when you were a kid?'),
       (5, N'What is the name of your favorite drink?'),
       (6, N'What was the name of your first love?'),
       (7, N'What did you score on the SAT?')
) 
AS Source ([SecurityQuestionId], [Text]) 
ON Target.[SecurityQuestionId] = Source.[SecurityQuestionId] 
WHEN MATCHED THEN 
UPDATE SET [Text] = Source.[Text] 
WHEN NOT MATCHED BY TARGET THEN 
INSERT ([SecurityQuestionId], [Text]) 
VALUES ([SecurityQuestionId], [Text]) 
WHEN NOT MATCHED BY SOURCE THEN 
DELETE;

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.