Create a stored procedure

This script creates a stored procedure that updates the serverstatus table. It can be run from the SQL Query Analyzer.

CREATE PROCEDURE Update_ServerStatus 
       @Servername Varchar(20), @OSStatus Varchar(11), 
       @PingStatus Varchar(11) , @harddiskstatus varchar(11) AS

declare @var1 varchar(11)
declare @var2 varchar(11)
declare @var3 varchar(11)


If @OSStatus= '' or @PingStatus = ''  or @harddiskstatus = ''
  begin 
   select @var1 = Osstatus, @var2 = PingStatus, 
   @var3 = harddiskstatus 
   from serverstatus
   where Servername = @servername
  end


DELETE FROM ServerStatus
WHERE ServerName =  @Servername

If @osstatus = ''  
Begin
	Set @osstatus = @var1
End
If @Pingstatus = '' 
Begin
	Set  @pingstatus = @var2
End
If @harddiskstatus = '' 
Begin
	Set  @harddiskstatus = @var3
End

Insert ServerStatus 
 (servername, OSStatus, PingStatus, harddiskstatus, DateTimeStamp) 
 VALUES 
  (@servername, @OSStatus, @PingStatus, @harddiskstatus,GetDate())
GO