1

我有以下插入触发器,它本质上是将插入中的重复行写入 QA/QC 表(IAW 业务要求)。

  INSERT dbo.TBL_LOCATIONS(
  Column1, Column2
  )
  SELECT 
  a.Column1,  a.Column2
  From
  (  
    SELECT  
   Column1,   Column2
     FROM inserted  
  ) AS a 
  end
GO

我正在尝试做的是根据插入表中插入的可能值的逻辑测试填充[Column1]一系列tbl_locations值,例如如果[a.Column1]是“1”,则在中插入“一些字符串” tbl_locations.Column1,如果[a.Column1]是“2 ", 然后在 中插入 "Some other string" tbl_locations.Column1, 如果是 "3", 然后在...[a.Column1]中插入 "Yet another string"tbl_locations.Column1

4

2 回答 2

1

或者,您可以尝试这样的事情:

INSERT INTO dbo.TBL_LOCATIONS (Column1, Column2)
SELECT
  s.Description,
  i.Column2
FROM inserted i
LEFT JOIN (
  VALUES
    (1, 'Polygon: Determination Made by GPS Survey'  ),
    (2, 'Polygon: Determination Derived from NWI'    ),
    (3, 'Polygon: Determination Made by Other Means' ),
    (4, 'Polygon: Legal Jurisdictional Determination')
) s (ID, Description)
ON i.Column1 = s.ID
于 2012-05-25T18:16:19.630 回答
0
         INSERT dbo.TBL_LOCATIONS( 
          Column1, Column2 
          ) 
          SELECT  
          a.Column1,  a.Column2 
          From 
          (   
            SELECT   
           Column1= case
        when Column1= 1 then 'Polygon: Determination Made by GPS Survey'
        when Column1= 2 then 'Polygon: Determination Derived from NWI' 
        when Column1= 3 then 'Polygon: Determination Made by Other Means'
        when Column1= 4 then 'Polygon: Legal Jurisdictional Determination'
        end ,
        Column2 
             FROM inserted   
          ) AS a  
          end 
GO
于 2012-05-25T13:10:31.400 回答