Moved SQL into a script