Connecting Tech Pros Worldwide Forums | Help | Site Map

How do i convert a column with id letters in a file to a number 1 or 0 in coldfusion

Newbie
 
Join Date: Dec 2008
Location: Philadelphia
Posts: 1
#1: Dec 5 '08
How do i convert a column with id letters in a file to a number 1 or 0 in coldfusion output....for example

'CON' or 'BUS' to be converted to an output of '0'and '1' (0 to represent CON and 1 for BUS)

The script is shown below the 'CustomerTypeID' column needs code that converts it from an "id" of ‘CON' or ‘BUS' to a "CustomerTypeId" of ‘0' or ‘1'. this is what the result i got when i ran the script below . I think it failed to insert to the table due to last column as shown below,not sure.



Error code



Expand|Select|Wrap|Line Numbers
  1. Error Code: 0
  2. Error Message 226 Transfer complete.
  3. rawinput length = 64 '8053717906', '15667154aa', 'CA', '0', 'CON' - Failed
  4. rawinput length = 32 '3104224249', '15667545aa', 'NJ', '1', 'BUS' - Failed
  5. Records inserted = 0
  6. Failed to insert = 2


Script


Expand|Select|Wrap|Line Numbers
  1. <cfloop condition="len(rawInput) gt 30">
  2. <!--- <cfset rowcnt=#rowcnt#+1> --->
  3. <cfset Row = mid(RawInput,1,find(chr(10),RawInput,1)-1)><!--- selects first row of text file --->
  4. rawinput length = <cfoutput>#len(rawInput)#</cfoutput>
  5. <cfset Tn=#trim(ListGetAt(row, 1, "|"))#>
  6. <cfset state=#trim(ListGetAt(row, 2, "|"))#>
  7. <cfset region=#trim(ListGetAt(row, 3, "|"))#>
  8. <cfset OrderNumber=#trim(ListGetAt(row, 4, "|"))#>
  9. <cfset id=#trim(ListGetAt(row, 5, "|"))#>
  10.  
  11.  
  12.  
  13. <cfif #region# eq 2><cfset region = 0></cfif>
  14.  
  15.  
  16.  
  17. <cfoutput>
  18. <cftry>
  19.  
  20. <cfquery name="insert" datasource="dispro">
  21. insert into DslPortOutOrders 
  22. (dslphonenumber, Ordernumber, state, eastregion, CustomerTypeId)
  23. values ('#tn#', '#Ordernumber#', '#state#', '#region#', '#id#')
  24. </cfquery>
  25.  
  26. <cfset insertcnt=#insertcnt#+1> 
  27. '#tn#', '#Ordernumber#', '#state#', '#region#', '#id#'<br />
  28. <cfcatch type="Any">
  29. <font color="##FF0000">'#tn#', '#Ordernumber#', '#state#', '#region#', '#id#' - Failed</font><br />
  30. <cfset Failcnt=#failcnt#+1>
  31. </cfcatch>
  32. </cftry>
  33. </cfoutput>
  34. <!--- Trims line just inserted from the text file. --->
  35. <cfset RawInput = mid(RawInput,find(chr(10),RawInput,1)+1,len(rawInput))>
  36. <!---<cfoutput>Length: #len(RawInput)#</cfoutput>--->
  37. </cfloop>

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Dec 5 '08

re: How do i convert a column with id letters in a file to a number 1 or 0 in coldfusion


Hi, welcome to Bytes!

You can use a simple cfif which checks the value and sets a variable to 0 or 1, then pass that value to the query.
Reply