A SQL statement that can perform INSERT, UPDATE and DELETE operations in a single statement.
Questions tagged [merge-statement]
52 questions
0
votes
1 answer
Update when relevant rows are not present in the source table
I have a merge statement like this:
MERGE DESTINATION
USING SOURCE WHERE
WHEN MATCHED AND THEN DELETE
WHEN MATCHED UPDATE
WHEN NOT MATCHED INSERT
This is working fine but I have one more condition i.e. I have to…

Zerotoinfinity
- 6,290
- 32
- 130
- 206
0
votes
1 answer
Updating inserted record within MERGE statement in SQL Server 2008 R2
I have following code in my SQL Server 2008 R2 stored procedure. In that stored procedure, I am copying one city to another city with it's family and persons.
Here I maintain family's source and target id in @FamilyIdMap.
left column indicates the…

IT ppl
- 2,626
- 1
- 39
- 56
0
votes
1 answer
Instead of Trigger on View using Merge doesn't apply table default values
I have an updateable view using an instead of trigger for insert/update. That trigger uses Merge. I'm finding that the Merge statement isn't applying the default constraints from the underlying physical table, although the merge documentation…

winnt93
- 43
- 1
- 6
0
votes
1 answer
MERGE output cursor of SP into table?
i have a Stored Procedure which returns output as a ref cursor. I would like to store the output in another table using the MERGE statement. I'm having problems however mixing all the statements together (WITH, USING, MERGE etc..).
Can somebody…

Ropstah
- 17,538
- 24
- 120
- 194
-1
votes
1 answer
Resolve the error: The multi-part identifier could not be bound?
I am creating a stored procedure and the final "When not matched" statement is throwing an error for the tmp.DelDate and tmp.DelUser fields. The "tmp" table is a User-Defined Table Type and the definition is below the sp code. 99 times out of 100,…

USMC6072
- 268
- 2
- 14
-2
votes
1 answer
MERGE statement in SQL Server 2008
I have a table student(int ID, nvarchar(10) studentName)
and a table user type myStudentType (int ID, nvarchar(10) studentName)
I need to create a stored procedure that accepts a myStudentType parameter (@students) and a parameter @newname…
-2
votes
1 answer
TSQL merge: doesn't skip duplicate
I used the following code to update or Insert record from one table to another but the insert statement doesn't skip when duplicate record. How can i bypass that?
I get the following error. I want to skip duplicate record and insert the new
Msg…

user6305775
- 57
- 5