ALTER PROCEDURE [sp_SensorCalibrationsInsert] @Id INT = NULL, @SensorSerialNumber NVARCHAR (50) = NULL, @SensorType TinyInt = NULL, @CalibrationDate DATETIME, @Username NVARCHAR (50), @LocalOnly BIT, @NonLinear BIT, @ModifyDate DATETIME, @IsProportional BIT, @RemoveOffset BIT, @ZeroMethod NVARCHAR (255), @CertificationDocuments NVARCHAR (2048), @InitialOffset NVARCHAR (MAX), @CalibrationRecords NVARCHAR (255), @new_id INT OUTPUT, @errorNumber INT OUTPUT, @errorMessage NVARCHAR (255) OUTPUT AS BEGIN SET @errorNumber = 0 SET @errorMessage = space(0) DECLARE @SensorId AS INT SET @SensorId = @Id IF( @Id IS NULL) BEGIN SELECT @SensorId = [Id] FROM [Sensors] WHERE [SensorType]=@SensorType AND [SerialNumber]=@SensorSerialNumber END IF( @SensorId IS NULL) BEGIN SET @errorNumber=1 SET @errorMessage='Sensor not found' END ELSE BEGIN DECLARE @CalibrationTypeId AS INT SET @CalibrationTypeId = [dbo].[foo_IdGetCalibrationType](@NonLinear, @CalibrationRecords) INSERT INTO [SensorCalibrations] ( [SensorId], [CalibrationDate], [Username], [LocalOnly], [NonLinear], [CalibrationTypeId], [CalibrationRecords], [ModifyDate], [IsProportional], [RemoveOffset], [ZeroMethod], [CertificationDocuments], [InitialOffset]) VALUES ( @SensorId, @CalibrationDate, @Username, @LocalOnly, @NonLinear, @CalibrationTypeId, @CalibrationRecords, @ModifyDate, @IsProportional, @RemoveOffset, @ZeroMethod, @CertificationDocuments, @InitialOffset) SET @new_id = SCOPE_IDENTITY() --IF(@CalibrationRecords != space(0) AND @SensorId !=0 AND @CalibrationTypeId != 0 AND @new_id !=0 ) --BEGIN -- EXEC [dbo].[sp_SensorCalibrationRecordProsess] @SensorId, @new_id, @CalibrationTypeId, @CalibrationRecords, @errorNumber output, @errorMessage output --END IF(@@error!=0) BEGIN SET @errorNumber = error_number() SET @errorMessage = error_message() END END END