SQL Server:Insert alter input上的触发器

时间:2016-05-26 22:42:02

标签: sql sql-server database sql-server-2008 triggers

我是SQL Server的新手,我正在努力创建一个能够满足我需要的触发器。

我们有一个表,在插入记录之前,我们想要操纵输入值。

示例表:

MyTable 
(   
    [RUID] INT IDENTITY(1,1),
    [CustomerName] nvarchar(200),
    [CustomerStatus] INT,
    [CustomerType] char(1),
    [OtherFields] nvarchar(100)
)

插入内容可能如下:

INSERT INTO MyTable ([CustomerName], [CustomerStatus], [CustomerType], [OtherFields]) 
 VALUES ('LName~FName', 2, 'A', 'Other Info')

我们无法控制进行插入的源系统(供应商产品在几年内即将推出,因此管理层并不想花费这笔钱来让它们改变它)但我们需要这样的事情发生。

插入的

CustomerStatus 是2x插入值

CustomerType - 无论发送的值如何,我们都希望使用' B'

的值覆盖

所有其他列保持原样。

因此,如果使用上面示例中的值发送插入,我们实际上希望这最终会出现在表中:

'LName~FName', 4, 'B', 'Other Info'

非常感谢您提供的任何帮助。

规格:

  • SQL Server 2008 R2标准版(虽然数据库处于SQL Server 2000兼容模式)

1 个答案:

答案 0 :(得分:1)

你基本上需要一个而不是触发器。代码看起来像......

App.controller('foodsController', function($scope) {

  $scope.foods = [{
    created_at_date: 6791234
  }, {
    created_at_date: 9837245
  }, {
    created_at_date: 1234755
  }];

  // create a method exposed to the scope for your template.

  $scope.orderBy = function(key, array) {
    // now you've received the array, you can sort it on the key in question.
    var sorted = array.sort(function(a, b) {
      return a[key] - b[key];
    });
    return sorted;
  }

});