A federal judge yesterday ordered a former official of an accounting firm to pay back a $45,000 profit he made when he bought Drug Fair stock based on insider information about a proposed merger with Gray Drug Stores Inc.

In a separete development yesterday, a San Antonio trucking firm, National City Lines, Inc., announced it intends to offer to purchase up to approximately one quarter of Gray Drug Stores' outstanding stock for $15 a share, an offer the drug chain said it would resist.

U.S. District Court Judge Pierre Leval of the Southern District of New York ordered Howard L. Davidowitz, an expert in the retailing and fashion business with Ernst & Whinney, one of the largest international accounting firms, to refrain from violating antifraud provisions of federal securities law and to return his profits to investors from whom he bought the stock.

Davidowitz, who was chairman of Ernst & Winney's retail industry committee and national director of its retail consulting group, consented to the court order without admitting or denying the SEC's charges. He also said he has begun to return the money.

According to the SEC's charges, Davidowitz learned of the proposed merger between the Alexandria-based Drug Fair chain and Gray Drugs of Cleveland froma partner in Ernst & Whinney on about Jan. 16. The partner had been contacted and asked to review Drug Fair's accounting work papers on behalf of Gray Drugs.

The SEC also charged that Davidowitz knew the review had to be completed by Jan. 21 in order for Gray's board of directors to consider the acquisition and that a purchase price of $20 a share was assumed -- compared with the then-current market price of $9.50 a share.

The conversation with the accounting firm partner occurred on a Friday, the SEC said. On the following Monday, Jan. 19, even before the markets opened, Davidowitz called his broker at Gruntal & Co. to place an order to buy 11,000 shares of Drug Fair stock. The broker bought the stock on Jan. 19 and 20 at prices ranging from $9.625 to $10 a share.

After the two families that controlled Drug Fair announced on Jan. 23 that they had received a bid for their shares, Davidowitz called his broker and told him to sell. The stock wold for $14 to $14.37 a share, netting Davidowitz a profit of $45,746.

After National City Lines' announcement that it intends to seek up to 650,000 shares of Gray's 2.6 million outstanding shares of stock, Gray's stock price climbed by 30.4 percent to $16.625, the largest percentage increase on the New York Stock Exchange yesterday.