• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 841
  • Last Modified:

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.
'**********************************************************************
'  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

Open in new window

0
austerhaus
Asked:
austerhaus
  • 4
  • 3
1 Solution
 
HoggZillaCommented:
You could also use the REPLACE function to change the unwanted char to an empty string.
0
 
HoggZillaCommented:
DTSDestination("customer_name") = REPLACE(UCASE(TRIM(DTSSource("Col013"))),Chr(160),"")
0
 
austerhausAuthor Commented:
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("Col008")), CHR(160), "")
        END IF

Can you tell me if that is the optimal thing to do?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
HoggZillaCommented:
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.
0
 
austerhausAuthor Commented:
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_name") = REPLACE(UCASE(TRIM(DTSSource("Col013"))),Chr(160),"")
IF ISNULL(DTSSource("Col008").value) THEN
        DTSDestination("mobile_num") = "0000000000"
    ELSE
        DTSDestination("mobile_num") = REPLACE(TRIM(DTSSource("Col008")), CHR(160), "")
        END IF
....
0
 
HoggZillaCommented:
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.
0
 
austerhausAuthor Commented:
Great, thank you for the assistance!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now