﻿ALTER PROCEDURE [dbo].[sp_DASUpdate]
			 @DASId					int			= 0
			,@SerialNumber			nvarchar(50) = null
			,@Type					int
			,@MaxModules			int
			,@MaxMemory				bigint
			,@MaxSampleRate			decimal(18,0)
			,@MinSampleRate			decimal(18,0)
			,@FirmwareVersion		nvarchar(50)
			,@CalDate				datetime
			,@ProtocolVersion		int
			,@LastModified			datetime
			,@LastModifiedBy		nvarchar(50)
			,@Version				int
			,@LocalOnly				bit
			,@LastUsed				datetime
			,@LastUsedBy			nvarchar(50)
			,@Connection			nvarchar(50)
			,@Channels				int
			,@Position				nvarchar(50)
			,@ChannelTypes			nvarchar(255)
			,@Reprogramable			bit
			,@Reconfigurable		bit
			,@IsModule				bit
			,@PositionOnDistributor	smallint
			,@PositionOnChain		smallint	
			,@Port					smallint	
			,@ParentDAS				nvarchar(50)
			,@FirstUseDate          datetime null
			,@TestId                int null
			,@GroupId               int null
			,@StandIn               bit null
			,@new_id				int				output
			,@errorNumber			int				output
			,@errorMessage			nvarchar(250)	output 
AS
BEGIN
	set @errorNumber = 0 
	set @errorMessage = space(0)

	SET NOCOUNT ON;
	if(@SerialNumber is null)
	begin 
		set @errorNumber = 15600
		set @errorMessage = 'An invalid parameter or option was specified for procedure'
	end
	else
	begin
		if(@DASId = 0)
		begin
			set @DASId = dbo.foo_IdGetDAS(@SerialNumber) 
		end
		SET @new_id = @DASId
		UPDATE [dbo].[DAS]
		   SET [Type]					=	@Type				
				,[MaxModules]			=	@MaxModules		
				,[MaxMemory]			=	@MaxMemory			
				,[MaxSampleRate]		=	@MaxSampleRate		
				,[MinSampleRate]		=	@MinSampleRate		
				,[FirmwareVersion]		=	@FirmwareVersion	
				,[CalDate]				=	@CalDate			
				,[ProtocolVersion]		=	@ProtocolVersion	
				,[LastModified]			=	@LastModified		
				,[LastModifiedBy]		=	@LastModifiedBy	
				,[Version]				=	@Version			
				,[LocalOnly]			=	@LocalOnly			
				,[LastUsed]				=	@LastUsed			
				,[LastUsedBy]			=	@LastUsedBy		
				,[Connection]			=	@Connection		
				,[Channels]				=	@Channels			
				,[Position]				=	@Position			
				,[ChannelTypes]			=	@ChannelTypes		
				,[Reprogramable]		=	@Reprogramable		
				,[Reconfigurable]		=	@Reconfigurable	
				,[IsModule]				=	@IsModule	
				,[PositionOnDistributor]=   @PositionOnDistributor	
				,[PositionOnChain]		=   @PositionOnChain		
				,[Port]					=   @Port					
				,[ParentDAS]			=   @ParentDAS
				,[FirstUseDate]         =   @FirstUseDate
				,[TestId]               =   @TestId
				,[GroupId]              =   @GroupId
				,[StandIn]              =   @StandIn
		 WHERE [DASId]					=	@DASId
	end
END
