Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a CHAR space to a NULL using function in DTS

Status
Not open for further replies.

DavidNPD

IS-IT--Management
Jan 30, 2006
2
US
I am doing a data conversion where i need to pull many fields from a SQL2000 database to another SQL 2000 database. I am using DTS activeX scripts to perform this. During the transfer I will be pulling data from various length CHAR fields to VARCHAR fields. When the source CHAR field is blank, I wish to insert a NULL into the destination VARCHAR field. Because there are varying lengths and MANY fields I would like to simplify my code to do this. Currently I use this to make this conversion, which works but notice that I need to explicitly show how large the string is. I would like to simplify this.
****************
Function Main()
Select Case DTSSource("WK_CITY")
Case " "
DTSDestination("area_code") = NULL
Case Else
DTSDestination("area_code") = RTrim( DTSSource("WK_CITY"))
End Select
Main = DTSTransformStat_OK
End Function

****************
I received this idea from another help site but we could not get it to function correctly. the idea is to create a small function and then call that from the individual rows, then I would not need to know the length of the CHAR field and would not have to have all those different size " " string entries. Can anybody see what is wrong with this function and why it does not work? it parses correctly but does not populate the nulls only the data where it exists.
***********************
Function Main()
DTSDestination("area_code") = GetValue(DTSSource("WK_CITY"))
Main = DTSTransformStat_OK
End Function

Function Getvalue(Value)
If LEN(Value) THEN
GetValue = Value
Else
GetValue = Null
End If
End Function
******************************
Thanks for any help in advance.
 
Just as additional, in Oracle the default action of a RTrim on a blank field is a NULL, that would be perfect for this, but that works in SQL only when you are compatiblity model below 70. I am not stuck on this function, is somebody know another simple way to perform the same for multiple fields that would also be a help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top