No sir the claim that he demolished temples isnt entirely true, to accoputn for war expenses must be fullfilled the hindus stockpiled theer wealth in the temples, hence just likr any invading army his also took booty, it quite diffrent to demolishing masjids like the indians dont in india due to pure hatred. He never stayed anywhere for long due to internal strife in ghazni etc , he wanst defaeted he conquered province by province and then returned the 17th time he stayed thats what you should actually say.
Following the defeat of the Rajput Confederacy, after deciding to retaliate for their combined resistance, Mahmud then set out on regular expeditions against them, leaving the conquered kingdoms in the hands of Hindu vassals annexing only the Punjab region. He also vowed to raid India every year. Thats why you say he failed sixteen tiem he didnt he just gave a few blows went back returned and kicked some more, simple as that .
refer tohttp://www.sscnet.ucla.edu/southasia/History/Mughals/mahmud_mughals.html " He launched aggressive expansionist campaigns, and is said to have invaded India no less than 17 times between 1000 and 1025 AD. His campaigns invariably took place during the hot summer season, and on each occasion Mahmud left India before the onset of the monsoons, which would have flooded the rivers of the Punjab and possibly trapped his troops."
so you see it was a military strategy not overrall withdrawal as you claim, as for the 800 claim, captain sher faced the 8 sikh regiment numbering between 450 to soem 1000 mena acordign to diffrent accounts since then the number 800 became commonly used to decsribe teh regiment hence i said 800 sikh regiment, il post the account as decribed by statemaster
StateMaster - Encyclopedia: Karnal Sher Khan