SQL 服务器 - 从结果 A 中删除结果 B,插入原始 table

SQL Server - Remove results B from results A, insert to original table

Table结构

我需要什么?

SQLFiddle.com

我可以想象这个过程,但我不知道如何在SQL中实现。

非常感谢任何帮助。

insert into transision

select 1051 as LanguageId ,your columns.......

from B

left join  A
on B.ModuleName != A.ModuleName and
B.Type != A.Type  and
B.Id != A.Id  and
B.ParentId != A.ParentId
where B.LanguageId !=1051

从满足所有这些条件的集合 B 中删除:

  • B.ModuleName = A.ModuleName
  • B.Type = A.Type
  • B.Id = A.Id
  • B.ParentId = A.ParentId

。等于这个

SELECT *
FROM Translation B
WHERE NOT EXISTS ( SELECT *
                   FROM Translation A
                   WHERE
                        A.LanguageId = 1051 
                    and B.ModuleName = A.ModuleName
                    and B.Type = A.Type
                    and B.Id = A.Id
                    and B.ParentId = A.ParentId
                )
and B.LanguageId <> 1051
  • 在集合B中,更改所有LanguageId = 1051

      SELECT B.*, 1051 as LenguajeID
      FROM Translation B
      <.. same as before ...>
    
  • 将集 B 插入原始翻译 table

      INSERT INTO Translation 
          SELECT [RowId],
            [ModuleName],
            [Type],
            [Id],
            [ParentId],
            1051 [LanguageId],
            [Text],
            [X],
            [Y],
            [Width],
            [Height],
            [Pending],
            [Remarks]
          FROM Translation B
          WHERE NOT EXISTS ( SELECT *
                             FROM Translation A
                             WHERE A.LanguageId = 1051 
                             and B.Type = A.Type
                             and B.Id = A.Id
                             and B.ParentId = A.ParentId
                             and B.ModuleName = A.ModuleName
                          )
          AND B.LanguageId <> 1051
    

SQL Fiddle Demo 仅供 select