我从下面的代码中收到此错误消息:
错误:无法将值NULL插入到'ACT_LABOR_COST'列中,表'[table name]';列不允许空值。更新失败。声明已经终止。
ACT_LABOR_COST
列是decimal(15,2), NOT NULL
,我正在尝试插入0.00,但是我收到了错误。
我的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=xxxxx;Initial Catalog=xxxxxx;Integrated Security=True");
SqlCommand insert = new SqlCommand(@"insert into labor_ticket
(TRANSACTION_ID,
WORKORDER_BASE_ID,
OPERATION_SEQ_NO,
TYPE,
SETUP_COMPLETED,
EMPLOYEE_ID,
DEPARTMENT_ID,
RESOURCE_ID,
HOURS_WORKED,
GOOD_QTY,
BAD_QTY,
TRANSACTION_DATE,
POSTING_CANDIDATE,
INDIRECT_CODE,
ACT_LABOR_COST,
ACT_BURDEN_COST,
CREATE_DATE)
VALUES(@TRANSACTION_ID,
@WORKORDER_BASE_ID,
@OPERATION_SEQ_NO,
@TYPE,
@SETUP_COMPLETED,
@EMPLOYEE_ID,
@DEPARTMENT_ID,
@RESOURCE_ID,
@HOURS_WORKED,
@GOOD_QTY,
@BAD_QTY,
@TRANSACTION_DATE,
@POSTING_CANDIDATE,
@INDIRECT_CODE,
@ACT_LABOR_COST,
@ACT_BURDEN_COST,
@CREATE_DATE)", conn);
insert.Parameters.AddWithValue("@TRANSACTION_ID", 78533);
insert.Parameters.AddWithValue("@WORKORDER_BASE_ID", "W14935");
insert.Parameters.AddWithValue("@OPERATION_SEQ_NO", 20);
insert.Parameters.AddWithValue("@TYPE", "R");
insert.Parameters.AddWithValue("@SETUP_COMPLETED", "Y");
insert.Parameters.AddWithValue("@EMPLOYEE_ID", "EZ0022");
insert.Parameters.AddWithValue("@DEPARTMENT_ID", "Operations");
insert.Parameters.AddWithValue("@RESOURCE_ID", "WC0VIBRA");
insert.Parameters.AddWithValue("@HOURS_WORKED", 1.50);
insert.Parameters.AddWithValue("@GOOD_QTY", 2.2000);
insert.Parameters.AddWithValue("@BAD_QTY", 0.0000);
insert.Parameters.AddWithValue("@TRANSACTION_DATE", "2016-11-04 01:00:00.000");
insert.Parameters.AddWithValue("@POSTING_CANDIDATE", "N");
insert.Parameters.AddWithValue("@INDIRECT_CODE", "X");
insert.Parameters.AddWithValue("@ACT_LABOR_COST", 0.00);
insert.Parameters.AddWithValue("@ACT_BURDEN_COST", 0.00);
insert.Parameters.AddWithValue("@CREATE_DATE", "2016-11-04 02:30:00.000");
try
{
conn.Open();
insert.ExecuteNonQuery();
Response.Write("labor ticket record inserted !");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
conn.Close();
}
}
此表有一个触发器:
go
SET quoted_identifier OFF
go
ALTER TRIGGER [dbo].[INSERT_LABOR_TICKET]
ON [dbo].[labor_ticket]
FOR INSERT
AS
SET nocount ON
DECLARE @nRcd INT
DECLARE @CostingStdLabor CHAR
DECLARE @CostingMethod CHAR
DECLARE @TYPE CHAR
DECLARE @MULTIPLIER_1 DEC(5, 3)
DECLARE @MULTIPLIER_2 DEC(5, 3)
DECLARE @POSTING_CANDIDATE CHAR
DECLARE @SETUP_COMPLETED CHAR
DECLARE @TRANSACTION_ID INT
DECLARE @WORKORDER_TYPE CHAR
DECLARE @WORKORDER_BASE_ID VARCHAR(30)
DECLARE @WORKORDER_LOT_ID VARCHAR(3)
DECLARE @WORKORDER_SPLIT_ID VARCHAR(3)
DECLARE @WORKORDER_SUB_ID VARCHAR(3)
DECLARE @OPERATION_SEQ_NO SMALLINT
DECLARE @CALC_END_QTY DEC(14, 4)
DECLARE @COMPLETED_QTY DEC(14, 4)
DECLARE @EST_LABOR_COST DEC(15, 2)
DECLARE @EST_BURDEN_COST DEC(15, 2)
DECLARE @STATUS CHAR
DECLARE @CLOSE_DATE DATETIME
DECLARE @NewCompletedQty DEC(14, 4)
DECLARE @QtyOver DEC(14, 4)
DECLARE @GOOD_QTY DEC(14, 4)
DECLARE @Ratio1 DEC(14, 4)
DECLARE @Ratio2 DEC(14, 4)
DECLARE @TotalLaborCost DEC(15, 2)
DECLARE @TotalBurdenCost DEC(15, 2)
DECLARE @LaborCost DEC(15, 2)
DECLARE @BurdenCost DEC(15, 2)
DECLARE @HOURS_WORKED DEC(7, 2)
DECLARE @HOURLY_COST DEC(15, 2)
DECLARE @BAD_QTY DEC(14, 4)
DECLARE @UNIT_COST DEC(15, 6)
DECLARE @BURDEN_PERCENT DEC(6, 3)
DECLARE @BURDEN_PER_HR DEC(15, 2)
DECLARE @BURDEN_PER_UNIT DEC(15, 6)
DECLARE @BUR_PER_OPERATION DEC(15, 2)
DECLARE @ACT_LABOR_COST DEC(15, 2)
DECLARE @ACT_BURDEN_COST DEC(15, 2)
DECLARE @SetupHrs DEC(7, 2)
DECLARE @RunHrs DEC(7, 2)
DECLARE @TRANSACTION_DATE DATETIME
SELECT @nRcd = 0
DECLARE labor_ticket_ins CURSOR local FOR
SELECT transaction_id,
type,
multiplier_1,
multiplier_2,
posting_candidate,
setup_completed,
Isnull(hours_worked, 0),
workorder_type,
workorder_base_id,
workorder_lot_id,
workorder_split_id,
workorder_sub_id,
operation_seq_no,
Isnull(good_qty, 0),
Isnull(hourly_cost, 0),
Isnull(bad_qty, 0),
Isnull(unit_cost, 0),
Isnull(burden_percent, 0),
Isnull(burden_per_hr, 0),
Isnull(burden_per_unit, 0),
Isnull(bur_per_operation, 0),
transaction_date
FROM inserted
OPEN labor_ticket_ins
FETCH labor_ticket_ins INTO @TRANSACTION_ID, @TYPE, @MULTIPLIER_1,
@MULTIPLIER_2, @POSTING_CANDIDATE, @SETUP_COMPLETED, @HOURS_WORKED,
@WORKORDER_TYPE, @WORKORDER_BASE_ID, @WORKORDER_LOT_ID, @WORKORDER_SPLIT_ID,
@WORKORDER_SUB_ID, @OPERATION_SEQ_NO, @GOOD_QTY, @HOURLY_COST, @BAD_QTY,
@UNIT_COST, @BURDEN_PERCENT, @BURDEN_PER_HR, @BURDEN_PER_UNIT,
@BUR_PER_OPERATION, @TRANSACTION_DATE
WHILE ( @nRcd = 0
AND @@FETCH_STATUS <> -1 )
BEGIN
SELECT @CostingStdLabor = costing_std_labor,
@CostingMethod = costing_method
FROM application_global
SELECT @CALC_END_QTY = calc_end_qty,
@COMPLETED_QTY = completed_qty,
@EST_LABOR_COST = est_atl_lab_cost,
@EST_BURDEN_COST = est_atl_bur_cost,
@STATUS = status,
@CLOSE_DATE = close_date
FROM operation
WHERE workorder_type = @WORKORDER_TYPE
AND workorder_base_id = @WORKORDER_BASE_ID
AND workorder_lot_id = @WORKORDER_LOT_ID
AND workorder_split_id = @WORKORDER_SPLIT_ID
AND workorder_sub_id = @WORKORDER_SUB_ID
AND sequence_no = @OPERATION_SEQ_NO
SELECT @NewCompletedQty = @COMPLETED_QTY + @GOOD_QTY
SELECT @QtyOver = @NewCompletedQty - @COMPLETED_QTY
IF @CostingMethod = 'S'
AND @CostingStdLabor = 'Q'
AND @TYPE != 'I'
BEGIN
SELECT @Ratio1 = 0
SELECT @Ratio2 = 0
IF @CALC_END_QTY != 0
BEGIN
SELECT @Ratio1 = @NewCompletedQty / @CALC_END_QTY
SELECT @Ratio2 = @QtyOver / @CALC_END_QTY
END
SELECT @TotalLaborCost = @EST_LABOR_COST * @Ratio1
SELECT @TotalBurdenCost = @EST_BURDEN_COST * @Ratio1
SELECT @LaborCost = @EST_LABOR_COST * @Ratio2
SELECT @BurdenCost = @EST_BURDEN_COST * @Ratio2
END
ELSE
BEGIN
SELECT @LaborCost = ( @HOURS_WORKED * @HOURLY_COST *
@MULTIPLIER_1 *
@MULTIPLIER_2 ) +
( (
@GOOD_QTY + @BAD_QTY ) * @UNIT_COST )
SELECT @BurdenCost = ( @LaborCost * ( @BURDEN_PERCENT / 100 ) )
+ (
@HOURS_WORKED * @BURDEN_PER_HR )
+ ( ( @GOOD_QTY + @BAD_QTY ) *
@BURDEN_PER_UNIT
)
+
@BUR_PER_OPERATION
END
IF ( @TYPE = 'I' )
SELECT @POSTING_CANDIDATE = 'Y'
SELECT @ACT_LABOR_COST = @LaborCost + .005
SELECT @ACT_BURDEN_COST = @BurdenCost + .005
UPDATE labor_ticket
SET posting_candidate = @POSTING_CANDIDATE,
act_labor_cost = @LaborCost,
act_burden_cost = @BurdenCost
WHERE transaction_id = @TRANSACTION_ID
IF @TYPE != 'I'
BEGIN
IF @TYPE = 'R'
BEGIN
SELECT @SETUP_COMPLETED = 'Y'
SELECT @SetupHrs = 0
SELECT @RunHrs = @HOURS_WORKED
END
ELSE
BEGIN
SELECT @SetupHrs = @HOURS_WORKED
SELECT @RunHrs = 0
END
IF @NewCompletedQty >= @CALC_END_QTY
BEGIN
SELECT @STATUS = 'C'
SELECT @CLOSE_DATE = @TRANSACTION_DATE
END
IF @CostingMethod = 'S'
AND @CostingStdLabor = 'Q'
UPDATE operation
SET act_atl_lab_cost = Round(@TotalLaborCost, 2),
act_atl_bur_cost = Round(@TotalBurdenCost, 2),
completed_qty = completed_qty + @GOOD_QTY,
deviated_qty = deviated_qty + @BAD_QTY,
act_setup_hrs = act_setup_hrs + @SetupHrs,
act_run_hrs = act_run_hrs + @RunHrs,
setup_completed = @SETUP_COMPLETED,
status = @STATUS,
close_date = @CLOSE_DATE
WHERE workorder_type = @WORKORDER_TYPE
AND workorder_base_id = @WORKORDER_BASE_ID
AND workorder_lot_id = @WORKORDER_LOT_ID
AND workorder_split_id = @WORKORDER_SPLIT_ID
AND workorder_sub_id = @WORKORDER_SUB_ID
AND sequence_no = @OPERATION_SEQ_NO
ELSE
UPDATE operation
SET act_atl_lab_cost = act_atl_lab_cost + Round(@LaborCost,
2),
act_atl_bur_cost = act_atl_bur_cost + Round(@BurdenCost
, 2)
,
completed_qty = completed_qty +
@GOOD_QTY,
deviated_qty = deviated_qty + @BAD_QTY,
act_setup_hrs = act_setup_hrs + @SetupHrs,
act_run_hrs = act_run_hrs + @RunHrs,
setup_completed = @SETUP_COMPLETED,
status = @STATUS,
close_date = @CLOSE_DATE
WHERE workorder_type = @WORKORDER_TYPE
AND workorder_base_id = @WORKORDER_BASE_ID
AND workorder_lot_id = @WORKORDER_LOT_ID
AND workorder_split_id = @WORKORDER_SPLIT_ID
AND workorder_sub_id = @WORKORDER_SUB_ID
AND sequence_no = @OPERATION_SEQ_NO
END
UPDATE work_order
SET desired_qty = desired_qty * 1
WHERE type = @WORKORDER_TYPE
AND base_id = @WORKORDER_BASE_ID
AND lot_id = @WORKORDER_LOT_ID
AND split_id = @WORKORDER_SPLIT_ID
AND sub_id = '0'
UPDATE equip_pm_schedule
SET invoice_flag = 'R'
WHERE workorder_type = @WORKORDER_TYPE
AND workorder_base_id = @WORKORDER_BASE_ID
AND workorder_lot_id = @WORKORDER_LOT_ID
AND workorder_split_id = @WORKORDER_SPLIT_ID
AND workorder_sub_id = @WORKORDER_SUB_ID
AND cust_order_id IS NOT NULL
UPDATE unp_mnt_calls
SET invoice_flag = 'R'
WHERE workorder_type = @WORKORDER_TYPE
AND workorder_base_id = @WORKORDER_BASE_ID
AND workorder_lot_id = @WORKORDER_LOT_ID
AND workorder_split_id = @WORKORDER_SPLIT_ID
AND workorder_sub_id = @WORKORDER_SUB_ID
AND cust_order_id IS NOT NULL
FETCH labor_ticket_ins INTO @TRANSACTION_ID, @TYPE, @MULTIPLIER_1,
@MULTIPLIER_2, @POSTING_CANDIDATE, @SETUP_COMPLETED, @HOURS_WORKED,
@WORKORDER_TYPE, @WORKORDER_BASE_ID, @WORKORDER_LOT_ID,
@WORKORDER_SPLIT_ID,
@WORKORDER_SUB_ID, @OPERATION_SEQ_NO, @GOOD_QTY, @HOURLY_COST,
@BAD_QTY,
@UNIT_COST, @BURDEN_PERCENT, @BURDEN_PER_HR, @BURDEN_PER_UNIT,
@BUR_PER_OPERATION, @TRANSACTION_DATE
END
DEALLOCATE labor_ticket_ins
IF ( @nRcd <> 0 )
RAISERROR('VMFG-%d error in trigger INSERT_LABOR_TICKET',16,-1,@nRcd)
IF ( @nRcd <> 0
OR @@ERROR <> 0 )
ROLLBACK TRANSACTION