Hello,
Viagra is used for erectile dysfunction but it should be taken under medical supervision. Moreover erectile dysfunction is due to many causes and treating the cause can help in erectile dysfunction. The causes are many like diabetes, depression, autonomic nervous system problem, excessive alcohol ingestion or tobacco smoking etc. You may need to consult your doctor to see which amongst these causes are responsible for your problem.
It is very difficult to precisely confirm a diagnosis without examination and investigations and the answer is based on the medical information provided. For exact diagnosis, you are requested to consult your doctor. I sincerely hope that helps. Take care and please do keep me posted on how you are doing.