From the above links supplied by Masato, this is one of those songs that has been added to and altered through the passage of time.Some of the lyrics and dates given substantiate the Queen Anne period of the Wars of the Spanish Succession. The only anomaly in some of them is the line of the chorus
"Through Flanders, Portugal and Spain"
While actions in this particular war did take place in Flanders, Germany, Italy and Spain - Portugal was not involved.
I think that this particular line comes from Napoleonic times. The tune and song were adopted by the 95th Rifles, long before John Tams wrote his version for the Sharpe series of television programmes - at least according to the Rifle Regiments museum in Winchester.
The Female Drummer is another example of soldiers marching songs that cover both the Napoleonic/French Revolutionary Wars and the Wars of the Spanish Succesion.