CONCORD, N.H. - A federal judge has struck down a state law that makes doctors' prescription-writing habits confidential, saying it violates the First Amendment.

Drug company sales representatives use the information to target particular doctors and tailor their sales pitches.

Signed last summer by Gov. John Lynch, the law made New Hampshire the first state to try to block those pitches by restricting access to data that identifies doctors and other prescribers.

Information containing prescribers' ZIP codes, location and medical specialties is allowed. The law does not prohibit information from being used for care management, clinical trials and education.

IMS Health Inc., headquartered in Norwalk, Conn. with significant operations in Plymouth Meeting, and Verispan L.L.C., headquartered in Yardley, filed a complaint in U.S. District Court asking a judge to declare it unconstitutional.

The companies, which collect, analyze and sell medical data, allege the law violates free speech rights, endangers public health and impedes research.

U.S. District Judge Paul Barbadoro agreed. He said in his ruling that the law "attempts to address important public policy concerns," but that when states "adopt speech restrictions as their method, courts must subject their efforts to closer scrutiny."

Robert Steinfeld, IMS senior vice president and general counsel, said: "We are very pleased with the judge's decision, and there are no losers in the outcome of this trial. Patients will benefit from a more transparent, safer and more competitive health-care system as a result of this ruling."

AARP, the New Hampshire Medical Society and the Department of Health and Human Services supported the law. Supporters said the ban would protect doctor-patient privacy and prevent salespeople from unduly influencing prescription choices.

"We're reviewing the decision and we'll decide whether to appeal," New Hampshire Attorney General Kelly Ayotte said Monday.