Query of Query Data Casting Problem
Hey all.
I am running into an issue where when attempting to run a query of query I get a datatype conversion error. The field causing the problem is a zip code. Some records have a short zip code like 00000 and others have the full length zip code like 00000-0000. Of course Coldfusion being as smart as it is, if it sees a short version first assumes the column is an integer. Then if it hits a long version it explodes trying to convert them. I tried using casting doesn't it doesn't seem to help. This is my query.
<cfquery name="CheckQuery" dbtype="query">
Select Name AS CheckNum,
Contact__r_name AS PayeeName,
contact__r_MailingCity AS City,
contact__r_MailingState AS State,
contact__r_MailingStreet AS Street,
CAST( contact__r_MailingPostalCode AS VARCHAR) AS ZIP,
contact__r_MailingCountry AS Country,
Payment_Amount__c AS PaymentValue,
Session__r_Project_Number__c AS Memo,
SESSION__R_ENDDATE AS CheckDate,
contact__r_pid__c as PID,
contact__r_Organization1__c AS Org
From ChecksToMake.Results
</cfquery>
Any thoughts on what else I can do to prevent this error? Thanks!
Oh, btw the exact error in the last instance was
"The value 55311-3116 cannot be converted to a number."
It referenced the line that query starts on.
