I don't know how your question is related to what kind of purpose is your forum for... anyway this SQL statement needs to be executed from the mySQL management tool like phpMyAdmin.
In my private collection I also have the add-on called "Mass Lock", it allows automatically lock all topics which have the latest reply posted earlier than the specified date. I.e. the date admin specifies, is the date AFTER no new replies were made. Both lock and unlock options are available.
But this add-on is not free.