moved sql query to variable