By embedding the SQL Statement into the script it runs fine.
Why doesn't it work when trying to populate the $SQLStatement variable with another variable containing the SQL Statement as a string?
Comment on Re: Win32::ODBC invalid string or buffer length
That points to a problem with the variable. If you're not doing so already, add use strict and use warnings to your program to make sure you're referencing what you think you're referencing. (In other words, that you're not clobbering a global or similar problems.)