sql - How to Delete the Existing data based on Where clause condition using Merge -


I have written a merge statement, where I am facing difficulty in removing the basis of data on the clause condition. Let me explain your scenario clearly

  1. For example, I have entered the date from source to target based on key condition. For example, enter a 10 digit.
  2. For example some changes are recorded and it has been updated through the merge statement.
  3. Based on the conditions, three records have now come for the same date key and need to be inserted and the rest should be removed for that date key.

    My example code:

      Delete Table1 with # Table1 # Table1 in CREATE TABLE # Table1 (ID INT, name VARCHAR (30), DateKey INT) Enter the value (ID, Name, DateKey) (1, 'Mohan', 20,131,231) # Table1 (Enter in ID, Name, DateKey) Value (2, 'Raj', 20,131,231) # Table1 (ID, Name, DateKey) ) Make Table1 (ID, Name, DateKey) value (4, 'Majza', 20131231) in Value (3, 'Majjaa', 20,131,231) # Table 2 (ID INT, name VARCHAR (30), DATEKEY INT) DE CLARE @i_DateKey INT set @i_DateKey = '20131231' # Table 2 Use of T as merge (pdp.id, pdp.Name, pdp.DATEKEY Selection # Table1 as PDP where (pdp.DateKe Y = @i_DateKey or @i_DateKey is Zero)) as T.ID = S.ID and T.DateKey = S.DateKey and T.NAME = S.NAME when the update sets after the match T.NAME = S Enter the value if the .NAME does not match the target (S.ID, S.Nom, SKKK), when the association did not match;  

    Now if I send the second row for the same date key, then the target table will be loaded with the rows, then it should be removed all 4 rows and reload the new line

I think this is a big mistake,

  ON T.ID = SID - I is not sure about this and T.DateKey = S.DateKey and T.NAME = S.NAME - please remove it as it will update after matching? When the matched set T.T.N. Name = S.NAME  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -