ALTER PROCEDURE [dbo].[sp_TestSetupsUpdate]
            @TestSetupName					nvarchar(50) = Null
           ,@SetupDescription				nvarchar(50)
           ,@AutomaticTestProgression		bit
           ,@AutomaticProgressionDelayMS	int
           ,@InvertTrigger					bit
           ,@InvertStart					bit
           ,@ViewDiagnostics				bit
           ,@VerifyChannels					bit
           ,@AutoVerifyChannels				bit
           ,@VerifyChannelsDelayMS			int
           ,@RecordingMode					smallint
           ,@SamplesPerSecond				float
           ,@PreTriggerSeconds				float
           ,@PostTriggerSeconds				float
		   ,@NumberOfEvents                 int
           ,@StrictDiagnostics				bit
           ,@RequireConfirmationOnErrors	bit
           ,@ROIDownload					bit
           ,@ViewROIDownload				bit
           ,@DownloadAll					bit
           ,@ViewRealtime					bit
           ,@RealtimePlotCount				smallint
		   ,@RegionsOfInterest				nvarchar(MAX)
           ,@ROIStart						float
           ,@ROIEnd							float
           ,@ViewDownloadAll				bit
           ,@Export							bit
           ,@ExportFormat					bigint
           ,@LabDetails						nvarchar(50)
           ,@UseLabDetails					bit
           ,@CustomerDetails				nvarchar(50)
           ,@UseCustomerDetails				bit
           ,@AllowMissingSensors			bit
           ,@AllowSensorIdToBlankChannel	bit
		   ,@CalibrationBehavior			smallint
           ,@LocalOnly						bit
           ,@LastModified					datetime
           ,@LastModifiedBy					nvarchar(50)
           ,@TurnOffExcitation				bit
           ,@TriggerCheckRealtime			bit
           ,@TriggerCheckStep				bit
           ,@PostTestDiagnostics			int
           ,@ExportFolder					nvarchar(150)
           ,@DownloadFolder					nvarchar(150)
           ,@CommonStatusLine				bit
           ,@SameAsDownloadFolder			bit
           ,@UploadData						bit
           ,@UploadDataFolder				nvarchar(150)
		   ,@UploadExportsOnly				bit
           ,@Settings						nvarchar(4000)
           ,@WarnOnBatteryFail				bit
           ,@Dirty							bit
           ,@Complete						bit
           ,@Error							nvarchar(255)
           ,@TestEngineerDetails			nvarchar(50)
           ,@UseTestEngineerDetails			bit
           ,@UserTags						varbinary(max)
           ,@DoAutoArm						bit
           ,@CheckoutMode					bit
           ,@ISFFile						nvarchar(4000)
           ,@QuitTestWithoutWarning			bit
           ,@NotAllChannelsRealTime			bit
           ,@NotAllChannelsViewer			bit
           ,@SuppressMissingSensorsWarning  bit
           ,@DoStreaming					bit
		   ,@ClockSyncProfileMaster			nvarchar(50)
		   ,@ClockSyncProfileSlave			nvarchar(50)
		   ,@ExtraProperties				nvarchar(max)
		   ,@MeasureSquibResistancesStep	bit
		   ,@TestSetupUniqueId				nvarchar(max)
		   ,@TestSetup						varbinary(MAX)
		   ,@LowgLVLTrigOn					bit
		   ,@LowgLVLTrigOnX                 bit
		   ,@LowgLVLTrigOnY                 bit
		   ,@LowgLVLTrigOnZ                 bit
		   ,@HighgLVLTrigOn                 bit
		   ,@HighgLVLTrigOnX                bit
		   ,@HighgLVLTrigOnY                bit
		   ,@HighgLVLTrigOnZ                bit
		   ,@AngAccelLVLTrigOn              bit
		   ,@AngAccelLVLTrigOnX             bit
		   ,@AngAccelLVLTrigOnY             bit
		   ,@AngAccelLVLTrigOnZ             bit
		   ,@ARSLVLTrigOn                   bit
		   ,@ARSLVLTrigOnX                  bit
		   ,@ARSLVLTrigOnY                  bit
		   ,@ARSLVLTrigOnZ                  bit
		   ,@LowgLVLTrigX                   float
		   ,@LowgLVLTrigY                   float
		   ,@LowgLVLTrigZ                   float
		   ,@HighgLVLTrigX					float
		   ,@HighgLVLTrigY                  float
		   ,@HighgLVLTrigZ                  float
		   ,@AngAccelLVLTrigX               float
		   ,@AngAccelLVLTrigY               float
		   ,@AngAccelLVLTrigZ               float
		   ,@ARSLVLTrigX                    float
		   ,@ARSLVLTrigY                    float
		   ,@ARSLVLTrigZ                    float
		   ,@HumidityLVLTrigOn              bit
		   ,@PressureLVLTrigOn              bit
		   ,@TemperatureLVLTrigOn           bit
		   ,@HumidityLVLTrigBelow           float
		   ,@HumidityLVLTrigAbove           float
		   ,@PressureLVLTrigBelow           float
		   ,@PressureLVLTrigAbove           float
		   ,@TemperatureLVLTrigBelow        float
		   ,@TemperatureLVLTrigAbove        float
		   ,@LowgRate                       int
		   ,@HighgRate                      int
		   ,@AngularRate                    int
		   ,@TempHumidPressRate             int
		   ,@BatterySaverModeOn             bit
		   ,@WakeupAndTriggerOn             bit
		   ,@WakeupTrigger                  smallint
		   ,@WakeUpMotionTimeout			int
		   ,@WakeUpMagnetTimeout			int
		   ,@WakeUpTimeSessionStart			datetime
		   ,@WakeUpTimeDuration				bigint
		   ,@TimedIntervalTrigOn			bit
		   ,@TimedIntervalDuration			int
		   ,@TimedIntervalEvents			int
		   ,@TimedIntervalFrequency			int
		   ,@TimedIntervalUnits				smallint
		   ,@RTCScheduleTrigOn				bit
		   ,@RTCScheduleStartDateTime		datetime
		   ,@RTCScheduleDuration			bigint
		   ,@new_id							int				output
		   ,@errorNumber					int				output
		   ,@errorMessage					nvarchar(250)	output 

AS
BEGIN
set @errorNumber = 0; 	set @errorMessage = space(0); set @new_id = 0;

/* Table (ans stored procedure) is too big... */

	begin try
		if(@TestSetupName is null)
		begin 
			set @errorMessage	= 'An invalid parameter or option was specified for procedure'
			set @errorNumber	= 15600
		end	
		else
		begin

			declare @TestSetupId int
			declare @TestEngineerId	int
			declare @LabratoryId	int 
			declare @CustomerId		int

			set @TestSetupId	= dbo.foo_IdGetTestSetup(@TestSetupName)
			set @CustomerId		= dbo.foo_IdGetCustomer(@CustomerDetails)
			IF @CustomerId <= 0
			BEGIN
				SET @CustomerId = null
			END
			set @LabratoryId	= dbo.foo_IdGetLabratory(@LabDetails)
			IF @LabratoryId <= 0
			BEGIN
				SET @LabratoryId = null
			END
			set @TestEngineerId	= dbo.foo_IdGetEngineer(@TestEngineerDetails);
			IF @TestEngineerId <= 0
			BEGIN
				SET @TestEngineerId = null
			END

			set @new_id = @TestSetupId

			UPDATE [dbo].[TestSetups]
			   SET [SetupDescription]					= @SetupDescription				
					,[AutomaticTestProgression] 		= @AutomaticTestProgression		
					,[AutomaticProgressionDelayMS] 		= @AutomaticProgressionDelayMS	
					,[InvertTrigger] 					= @InvertTrigger					
					,[InvertStart] 						= @InvertStart					
					,[ViewDiagnostics] 					= @ViewDiagnostics				
					,[VerifyChannels] 					= @VerifyChannels					
					,[AutoVerifyChannels] 				= @AutoVerifyChannels				
					,[VerifyChannelsDelayMS] 			= @VerifyChannelsDelayMS			
					,[RecordingMode] 					= @RecordingMode					
					,[SamplesPerSecond] 				= @SamplesPerSecond				
					,[PreTriggerSeconds] 				= @PreTriggerSeconds				
					,[PostTriggerSeconds] 				= @PostTriggerSeconds
					,[NumberOfEvents]				    = @NumberOfEvents				
					,[StrictDiagnostics] 				= @StrictDiagnostics				
					,[RequireConfirmationOnErrors] 		= @RequireConfirmationOnErrors	
					,[ROIDownload] 						= @ROIDownload					
					,[ViewROIDownload] 					= @ViewROIDownload				
					,[DownloadAll] 						= @DownloadAll					
					,[ViewRealtime] 					= @ViewRealtime					
					,[RealtimePlotCount] 				= @RealtimePlotCount
					,[RegionsOfInterest]				= @RegionsOfInterest				
					,[ROIStart] 						= @ROIStart						
					,[ROIEnd] 							= @ROIEnd							
					,[ViewDownloadAll] 					= @ViewDownloadAll				
					,[Export] 							= @Export							
					,[ExportFormat] 					= @ExportFormat					
					,[CustomerId]						= @CustomerId		
					,[LabratoryId] 						= @LabratoryId
					,[TestEngineerId]					= @TestEngineerId	
					,[LabDetails] 						= @LabDetails						
					,[UseLabDetails] 					= @UseLabDetails					
					,[CustomerDetails] 					= @CustomerDetails				
					,[UseCustomerDetails] 				= @UseCustomerDetails				
					,[AllowMissingSensors] 				= @AllowMissingSensors			
					,[AllowSensorIdToBlankChannel] 		= @AllowSensorIdToBlankChannel
					,[CalibrationBehavior]				= @CalibrationBehavior	
					,[LocalOnly] 						= @LocalOnly						
					,[LastModified] 					= @LastModified					
					,[LastModifiedBy] 					= @LastModifiedBy					
					,[TurnOffExcitation] 				= @TurnOffExcitation				
					,[TriggerCheckRealtime] 			= @TriggerCheckRealtime			
					,[TriggerCheckStep] 				= @TriggerCheckStep				
					,[PostTestDiagnostics] 				= @PostTestDiagnostics			
					,[ExportFolder] 					= @ExportFolder					
					,[DownloadFolder] 					= @DownloadFolder					
					,[CommonStatusLine] 				= @CommonStatusLine				
					,[SameAsDownloadFolder] 			= @SameAsDownloadFolder			
					,[UploadData] 						= @UploadData						
					,[UploadDataFolder] 				= @UploadDataFolder
					,[UploadExportsOnly]				= @UploadExportsOnly				
					,[Settings] 						= @Settings						
					,[WarnOnBatteryFail] 				= @WarnOnBatteryFail				
					,[Dirty] 							= @Dirty							
					,[Complete] 						= @Complete						
					,[ErrorMessage] 					= @Error
					,[TestEngineerDetails] 				= @TestEngineerDetails			
					,[UseTestEngineerDetails] 			= @UseTestEngineerDetails			
					,[UserTags] 						= @UserTags						
					,[DoAutoArm] 						= @DoAutoArm						
					,[CheckoutMode] 					= @CheckoutMode					
					,[ISFFile] 							= @ISFFile						
					,[QuitTestWithoutWarning] 			= @QuitTestWithoutWarning			
					,[NotAllChannelsRealTime] 			= @NotAllChannelsRealTime			
					,[NotAllChannelsViewer] 			= @NotAllChannelsViewer			
					,[SuppressMissingSensorsWarning] 	= @SuppressMissingSensorsWarning 
					,[DoStreaming] 						= @DoStreaming
					,[ClockSyncProfileMaster]			= @ClockSyncProfileMaster
					,[ClockSyncProfileSlave]			= @ClockSyncProfileSlave
					,[ExtraProperties]					= @ExtraProperties
					,[MeasureSquibResistancesStep]		= @MeasureSquibResistancesStep
					,[TestSetupUniqueId]				= @TestSetupUniqueId
					,[TestSetup]						= @TestSetup
					,[LowgLVLTrigOn]					= @LowgLVLTrigOn
					,[LowgLVLTrigOnX]					= @LowgLVLTrigOnX
					,[LowgLVLTrigOnY]					= @LowgLVLTrigOnY
					,[LowgLVLTrigOnZ]					= @LowgLVLTrigOnZ
					,[HighgLVLTrigOn]					= @HighgLVLTrigOn
					,[HighgLVLTrigOnX]					= @HighgLVLTrigOnX
					,[HighgLVLTrigOnY]					= @HighgLVLTrigOnY
					,[HighgLVLTrigOnZ]					= @HighgLVLTrigOnZ
					,[AngAccelLVLTrigOn]				= @AngAccelLVLTrigOn
					,[AngAccelLVLTrigOnX]				= @AngAccelLVLTrigOnX
					,[AngAccelLVLTrigOnY]				= @AngAccelLVLTrigOnY
					,[AngAccelLVLTrigOnZ]               = @AngAccelLVLTrigOnZ
					,[ARSLVLTrigOn]						= @ARSLVLTrigOn
					,[ARSLVLTrigOnX]					= @ARSLVLTrigOnX
					,[ARSLVLTrigOnY]					= @ARSLVLTrigOnY
					,[ARSLVLTrigOnZ]                    = @ARSLVLTrigOnZ
					,[LowgLVLTrigX]						= @LowgLVLTrigX
					,[LowgLVLTrigY]						= @LowgLVLTrigY
					,[LowgLVLTrigZ]						= @LowgLVLTrigZ
					,[HighgLVLTrigX]					= @HighgLVLTrigX
					,[HighgLVLTrigY]					= @HighgLVLTrigY
					,[HighgLVLTrigZ]					= @HighgLVLTrigZ
					,[AngAccelLVLTrigX]					= @AngAccelLVLTrigX
					,[AngAccelLVLTrigY]					= @AngAccelLVLTrigY
					,[AngAccelLVLTrigZ]					= @AngAccelLVLTrigZ
					,[ARSLVLTrigX]						= @ARSLVLTrigX
					,[ARSLVLTrigY]						= @ARSLVLTrigY
					,[ARSLVLTrigZ]						= @ARSLVLTrigZ
					,[HumidityLVLTrigOn]				= @HumidityLVLTrigOn
					,[PressureLVLTrigOn]				= @PressureLVLTrigOn
					,[TemperatureLVLTrigOn]				= @TemperatureLVLTrigOn
					,[HumidityLVLTrigBelow]				= @HumidityLVLTrigBelow
					,[HumidityLVLTrigAbove]				= @HumidityLVLTrigAbove
					,[PressureLVLTrigBelow]				= @PressureLVLTrigBelow
					,[PressureLVLTrigAbove]				= @PressureLVLTrigAbove
					,[TemperatureLVLTrigBelow]			= @TemperatureLVLTrigBelow
					,[TemperatureLVLTrigAbove]			= @TemperatureLVLTrigAbove
					,[LowgRate]							= @LowgRate
					,[HighgRate]						= @HighgRate
					,[AngularRate]						= @AngularRate
					,[TempHumidPressRate]				= @TempHumidPressRate
					,[BatterySaverModeOn]				= @BatterySaverModeOn
					,[WakeupAndTriggerOn]				= @WakeupAndTriggerOn
					,[WakeupTrigger]					= @WakeupTrigger
					,[WakeUpMotionTimeout]				= @WakeUpMotionTimeout
					,[WakeUpMagnetTimeout]				= @WakeUpMagnetTimeout
					,[WakeUpTimeSessionStart]			= @WakeUpTimeSessionStart
					,[WakeUpTimeDuration]				= @WakeUpTimeDuration
					,[TimedIntervalTrigOn]				= @TimedIntervalTrigOn
					,[TimedIntervalDuration]			= @TimedIntervalDuration
					,[TimedIntervalEvents]				= @TimedIntervalEvents
					,[TimedIntervalFrequency]			= @TimedIntervalFrequency
					,[TimedIntervalUnits]				= @TimedIntervalUnits
					,[RTCScheduleTrigOn]				= @RTCScheduleTrigOn
					,[RTCScheduleStartDateTime]			= @RTCScheduleStartDateTime
					,[RTCScheduleDuration]				= @RTCScheduleDuration
			 WHERE [TestSetupId]						= @TestSetupId
		end
		end try
		begin catch
			set @errorMessage	= error_message()
			set @errorNumber	= error_number()
		end catch;
END