My friend that drank alcohol daily for years, and quit by transitioning to pot, had the same problem as you. He went to the doctor and learned that drinking regularly causes the intestines to lose their nutrient absorption ability, and inhibits gluconeogenesis. The result is lack of energy & erectile dysfunction, amongst other things. When you have this condition and take Viagra, very, very little is absorbed, so it doesn't work.
The cool thing is within 3-4 days of stopping drinking, he had a lot more energy and woke up with a boner ( no pills ) no joke.
More info
Good luck