How to auto reset Queue number from 1 to 99

I modified something I put together in the past:
see this post for usage:

function get()
{
  var q = "SELECT Value From dbo.ProgramSettingValues WHERE Name = 'SequenceNumber'";
  var r = sql.Query(q).First;
  var sequenceNumber = r;
  
  if (r == null)
  {
    var q = "INSERT INTO dbo.ProgramSettingValues (Value, Name) VALUES ('1', 'SequenceNumber')";
    sql.Exec(q);
    
    sequenceNumber = 1;
  }
  else if (sequenceNumber == 99)
  {
    sequenceNumber = 1;
  }
  else
  {
    sequenceNumber++;
  }
  
  q = "UPDATE dbo.ProgramSettingValues SET Value = '"+sequenceNumber+"' WHERE Name = 'SequenceNumber'";
  sql.Exec(q);
  
  //return Helper.Format(sequenceNumber,'00');
  return sequenceNumber;
}

uncomment line 26 and comment line 27 if you need leading zeros (e.g. 01, 02, 03 etc.)