The U.S. Court of Appeals yesterday upheld last year's conviction of former D.C. Superior Court Judge Robert H. Campbell on a charge that he received a gift from a local construction firm, saying that "justice has served Judge Campbell better than he served it."

In a detailed 26-page opinion, the three-judge appeals court panel also unanimously affirmed Judge Thomas A. Flannery's decision to sentence Campbell to serve three months to two years in prison. Campbell, who resigned from the local court in 1978 because of a medical disability, can ask the full 10-member appeals court to hear his case or he can seek review in the U.S. Supreme Court.

In its decision yesterday, the appeals court also upheld the conviction of Excavation Construction, Inc., a Bladensburg, Md., construction firm found guilty by the same jury of giving an illegal gratuity to Campbell while he was on the bench. Flannery has fined the company $10,000.

The gift that was the focus of both convictions consisted of the services of Excavation Construction employes, who assisted Campbell in a move of his household goods in August 1975, while he was a judge. The prosecution contended the move was valued at $300.

Campbell said he paid the workmen $60 for their help, but the court of appeals said yesterday there was "credible evidence" during his six-week trial to conclude that the money was a tip, that the move was arranged earlier with an Excavation Construction employe and that Campbell knew that the movers' services were a "gratuity rendered for or because of Campbell's official acts."

Assistant U.S. attorneys John P. Hume and Carol E. Bruce contended during the trial that Campbell had taken gifts and money from the firm in exchange for lenient treatment of hundreds of dollars of overweight truck tickets issued to the firm.

Campbell, Excavation Construction, and company general manager Larry A. Campbell (no relation to the former judge) were charged with conspiracy, bribery and racketeering. All three were acquitted of those charges, but the jury found them guilty of the single, less serious offense involving the move.

Judge Campbell did not testify at his trial but told news reporters that he believed the government had a vendetta against him. At sentencing, Campbell told Flannery, "I am not a corrupt judge."

Flannery later acquitted Larry Campbell, finding that there was no evidence to support the jury's verdict against him. The government has asked the court of appeals to reinstate that conviction. That case is still pending.

The appeals court, in its opinion yesterday, upheld Flannery's decision to sentence Judge Campbell not just on the allegation involving the move but on all the evidence he heard during the trial, even though Campbell had been acquitted of those charges. The appeals court noted that at the time of sentencing Flannery said the case "revealed that this was just one incident in a pattern of corruption which had been going on for a number of years."

Campbell's lawyer, R. Kenneth Mundy, had argued that Flannery's action effectively denied his client the benefit of the jurors' ultimate decision that he was not guilty of some charges.

Judge Abner Mikva, writing for the appeals court, said however that Flannery's statement of reasons for his sentencing decision was sufficient to support his broad approach to what Mikva called "the arduous sentencing task in this case."

Mikva, joined by Judges Ruth Bader Ginsburg and Edward A. Tamm, also rejected arguments by Campbell and Excavation Construction that the verdict should be set aside because one juror, the lone holdout for acquittal, disclosed that the unanimous verdict in the case had only been reached after she agreed to a compromise.