Improved GetTypeForQueryVariable