You’ve got to learn how to deal with workplace jerks if you’re going to advance professionally — and preserve your sanity.

Robert Sutton, professor of management at Stanford University and author of “The No Asshole Rule,” spoke to a number of individuals who have coped with less than ideal coworkers for his upcoming book “The Asshole Survival Guide.

His sources included people who have worked with back-stabbers, incompetent and abusive bosses, and even one man who dealt with a noisy coworker who, according to a decibel meter, was as loud as cutting metal.

He said that, in many cases, it’s best to either avoid working with jerks in the first place or quit and move on.

But that evasive maneuvering isn’t always warranted — or possible for everyone.

With that in mind, Sutton broke down seven strategies for surviving the worst people in your office:

1. Look on the bright side

Sutton described the experience of a young lawyer who worked for a federal judge as part of a two-year clerkship. Her coworkers and boss were incredibly hard to deal with, but if she quit, she would have been committing career suicide. What’s more, she wouldn’t have been able to pay off her student loans.

Sutton said the young lawyer coped by using a cognitive behavioral trick — imagining herself at the end of her clerkship.

“When you’re in a difficult situation, if you can say to yourself, ‘If I can just get through tonight and look back on it over the weekend, six months, a year from now,’ stressful situations actually do much less damage on our mental and physical health,” Sutton told Business Insider.

Another example of cognitive distancing that Sutton recommends is trying to find humor in terrible situations.

“That always helps,” he said. “It’s amazing. You start laughing at people. That’s certainly what I do with some of my more difficult colleagues at Stanford.”

2. Physically avoid the worst people at work

Switch desks to get away from your annoying neighbor. Sit as far away from the rudest person in the office during meetings. Try to change up your schedule to avoid running into your workplace enemy in the kitchen.

The less you come into contact with workplace jerks, the better, said Sutton.

3. Exert power

If you have power over a colleague who’s behaving badly at work, then take a stand. Sutton cited the example of Paul Purcell, the former CEO and current chairman of wealth management firm Robert W. Baird.

“He tells people during interviews, ‘If I discover you’re an a——, I’m going to fire you,'” he said. “And he does.”

If you don’t take action, your complacency could erode workplace morale.

4. Collect evidence

Sutton said that documenting your experience with terrible coworkers is crucial, especially if the situation morphs into a legal or HR matter.

“That doesn’t always mean you’re going to win for sure, but it increases the odds,” Sutton said.

He cited the case of former Fox News anchor Gretchen Carlson, who checked the legality of recording someone without their permission and recorded her interactions with Roger Ailes, Business Insider reported.

Using the tapes, Carlson was able to prove her harassment case against her boss. Ailes was subsequently ousted from the network.

5. Talk it out

Sutton said that workplace jerks tend to come in two varieties — clueless and strategic. Strategic jerks behave badly to get ahead. Clueless jerks are legitimately unaware of the impact their behavior is having on others.

“If you’re dealing with someone who’s unintentionally an a—— and is sort of clueless, in that case, have that backstage conversation with them where you say, ‘You’re making me feel bad when you do this, can you possibly change your behavior?'” Sutton said. “That can be very effective.”

He described meeting a female executive vice president who shared that her CEO had a habit of only interrupting the women in the room during meetings with his senior team.

“What she and her colleague did was, they counted how many interruptions happened during a meeting and they just brought him the information,” Sutton said. “He didn’t realize he was doing it and he changed his behavior.”

6. Team up

For his latest book, Sutton talked with a team of dog catchers who had to deal with a racist colleague with an explosive temper. When their boss refused to take action against the woman in question, the team got together and formed an alliance to document the issues and oust their coworker.

“They wrote what they called the ‘a—— diaries’ and they went to their bosses with this documentation and this dog catcher was gone in a few days,” he said. “If it’s a coworker and your bosses aren’t helping you, that’s where the combination of having a posse and documentation often helps.”

7. Stand up for yourself

Sutton said that, in some cases, you’re going to have to fight it out with your workplace’s resident jerk — especially if they’re the “kind of person who only can accept strength or nastiness.”

“I’m a big believer in fighting, but I’m also a big believer that if you’re going to fight a coworker, you don’t want to do it if you think you’re going to lose,” Sutton said. “You’ve got to take time, talk to people who you trust, and assess the situation before you go to war.”

So ensure that you’ve tried other options, connected with allies, and accrued appropriate documentation before you actually start calling people out at work.

Originally published on www.businessinsider.com.

More from Business Insider:

11 things everyone should start doing in their 30s

15 cool small businesses that make people healthier, wealthier, smarter, and happier

A Harvard Business School graduate and startup founder says her best business lessons came from her worst mistakes

Follow us here and subscribe here for all the latest news on how you can keep Thriving.

Stay up to date or catch-up on all our podcasts with Arianna Huffington here.