New function for SQL string generation