austerhaus
asked on
Strip leading / trailing whitespace from strings in DTS Visual Basic Transformation script
Hello,
I have the attached ActiveX script that imports data into my table. The problem I am encountering is that the source data (a text file) contains leading a ASCII character 160 at the start of each value. Unfortunately, the TRIMs do not remove these characters. Is it possible to get rid of these in the transformation script? If so, how? I am a novice when it comes to ActiveX, so detailed assistance is appreciated. Please let me know if any additional detail is required.
I have the attached ActiveX script that imports data into my table. The problem I am encountering is that the source data (a text file) contains leading a ASCII character 160 at the start of each value. Unfortunately, the TRIMs do not remove these characters. Is it possible to get rid of these in the transformation script? If so, how? I am a novice when it comes to ActiveX, so detailed assistance is appreciated. Please let me know if any additional detail is required.
'**********************************************************************
' Visual Basic Transformation Script
' Copy each source column to the
' destination column
'************************************************************************
Function Main()
DTSDestination("run_dt") = TRIM(CDATE(DTSSource("Col001")))
DTSDestination("region_cd") = UCASE(TRIM(DTSSource("Col002")))
DTSDestination("location_cd") = TRIM(DTSSource("Col003"))
DTSDestination("area_cd") = UCASE(TRIM(DTSSource("Col004")))
DTSDestination("rep_id") = UCASE(TRIM(DTSSource("Col005")))
DTSDestination("order_num") = TRIM(DTSSource("Col006"))
DTSDestination("order_type") = UCASE(TRIM(DTSSource("Col007")))
DTSDestination("mobile_num") = TRIM(DTSSource("Col008"))
DTSDestination("manager_id") = UCASE(TRIM(DTSSource("Col009")))
DTSDestination("e_cd") = UCASE(TRIM(DTSSource("Col010")))
DTSDestination("item_cd") = UCASE(TRIM(DTSSource("Col011")))
DTSDestination("item_dt") = TRIM(CDATE(DTSSource("Col012")))
DTSDestination("customer_name") = UCASE(TRIM(DTSSource("Col013")))
DTSDestination("add_offer") = UCASE(TRIM(DTSSource("Col014")))
DTSDestination("disc_amt") = TRIM(DTSSource("Col015"))
DTSDestination("retail_amt") = TRIM(DTSSource("Col016"))
DTSDestination("remarks") = LCASE(TRIM(DTSSource("Col017")))
DTSDestination("disc_desc") = UCASE(TRIM(DTSSource("Col018")))
Main = DTSTransformStat_OK
End Function
You could also use the REPLACE function to change the unwanted char to an empty string.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you for the fast reply. It seems that there are errors thrown when a value is null. However, I was able to get around that using:
IF ISNULL(DTSSource("Col008") .value) THEN
DTSDestination("mobile_num ") = "0000000000"
ELSE
DTSDestination("mobile_num ") = REPLACE(TRIM(DTSSource("Co l008")), CHR(160), "")
END IF
Can you tell me if that is the optimal thing to do?
IF ISNULL(DTSSource("Col008")
DTSDestination("mobile_num
ELSE
DTSDestination("mobile_num
END IF
Can you tell me if that is the optimal thing to do?
Is this optimal, i guess that depends on the number of records. It could be quicker to remove the spaces and unwanted characters in the transformation but this is fine.
ASKER
I am not sure what you mean by "remove the spaces and unwanted characters in the transformation". The code I posted (see below) is contained in the transformation script. Am I missing something?
...
DTSDestination("customer_n ame") = REPLACE(UCASE(TRIM(DTSSour ce("Col013 "))),Chr(1 60),"")
IF ISNULL(DTSSource("Col008") .value) THEN
DTSDestination("mobile_num ") = "0000000000"
ELSE
DTSDestination("mobile_num ") = REPLACE(TRIM(DTSSource("Co l008")), CHR(160), "")
END IF
....
...
DTSDestination("customer_n
IF ISNULL(DTSSource("Col008")
DTSDestination("mobile_num
ELSE
DTSDestination("mobile_num
END IF
....
Oh, sorry. I don't why I was thinking it was an ActiveX script. This is good the way you have it. I can't think of a better way.
ASKER
Great, thank you for the assistance!