USE [Database]

IF OBJECT_ID('[Procedures].[insert_product_write_off_record]', 'P') IS NOT NULL
  DROP PROCEDURE [Procedures].[insert_product_write_off_record];
GO
CREATE PROCEDURE [Procedures].[insert_product_write_off_record]
  @barcode_product_value_id             AS INT,
  @reason_id                            AS INT,
  @count                                AS INT,
  @datetime                             AS DATETIME,
  @inserted_product_write_off_record_id AS INT = NULL OUTPUT
AS
  BEGIN TRANSACTION;
    INSERT INTO [Tables].[product_write_off_records]([barcode_product_value_id], [reason_id], [count], [datetime])
    VALUES (@barcode_product_value_id, @reason_id, @count, @datetime);
    SET @inserted_product_write_off_record_id = SCOPE_IDENTITY();
  COMMIT TRANSACTION;
GO