But he still does so, sometines in very provocative and sarcastic manner.
I've been through this too. I hated it (and still do) and it annoyed me to the point I was rude. Instantly rude, "[ self-censored ]" (won't write the words here, of course, but you get the idea...). Far above what was certainly needed at that time. And I have never heard of him anymore, but I had an enemy at the workplace. No more problem with him, but bad reputation for "having an attitude, can't take a joke, and so on...". No need to tell you that what I had done was too much, like "killing a fly with a sledghammer". Bad idea. I needed to find a better way...
Second time (years later, another company, but same kind of know-it-all-and-above-all-funny-jerk), I wanted another approach, and used a similar technic: provocative and sarcastic.
When the guy asked his question, I first ignored him and walked by. Second time, I stopped right away, stood up in front of him, hands in my back (like you do in the Army, when you report to someone), my gaze fixed in front of me, and said: "My name is PaulD - Front-end developer at Company X - SSN 772-00-1324" (1). Repeat as needed anytime they say something or ask a question. They'll give up and move on. At one point, they will, believe me. The best is when some people are listening / watching. End with a smile, a wink, turn back and walk... :)
You act like a POW and won't answer any question, just calling The Geneva Convention. With creativity, you can also invoke Miranda warning or The Fifth Amendment or any other private/legal/human right from your country. And use it in a funny way to dismiss their questions. Your message is really clear here! No matter what you ask, the only thing you'll get is that answer.
I did that the second time, and it was much better, as I was seen at the funniest guy (of the two 2) by other staff members, who laughed. Some of them even said they never dared to answer, but considered his behavior like bullying. Anyway, for me, the result was the same, the "smart guy" left me alone, but it was not because I used a nuclear option. Much better ;)
I've never found another way, but have to warn you that you won't make friends that way. You need to set boundaries in one way or another, I (sadly) never achieved that the smooth way, because they usually don't take "no" as an answer. But you can stop them by returning the gun against them.
1: stands for "Social Security Number" (772 is an unused sequence - 00 is never used therefore this number can't by anyone's)
2: no need to say that I was indeed the funniest of the whole team, of course :D