dbTalk Databases Forums  

Flat File Import and Null Values

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Flat File Import and Null Values in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gary Helriegel
 
Posts: n/a

Default Flat File Import and Null Values - 08-03-2006 , 01:14 AM






Hi all,

This is my first time posting, as well as my first time using DTS. I find myself
in a bit of a quandary. I'm trying to import data from a flatfile into a SQL
database, using the ActiveX VBscript engine. I want the fields which are nothing
but spaces to be true 'null' values in SQL. I'm using a function which sets any
field which contains nothing but spaces equal to "" (empty string). In the case
of the numeric fields, this works perfectly. However, the char and varchar field
types seem to insert an empty value, but not a null. I've got the checkbox for
'keep null values' turned on. How would I go about inserting a null value into
these fields?
Any help would be greatly appreciated.

Thanks in advance,
~Gary

--
Posted via a free Usenet account from http://www.teranews.com


Reply With Quote
  #2  
Old   
Davide
 
Posts: n/a

Default Re: Flat File Import and Null Values - 08-03-2006 , 01:59 AM






Hello Gary,

Quote:
Hi all,

This is my first time posting, as well as my first time using DTS. I
find myself
in a bit of a quandary. I'm trying to import data from a flatfile into
a SQL
database, using the ActiveX VBscript engine. I want the fields which
are nothing
but spaces to be true 'null' values in SQL. I'm using a function which
sets any
field which contains nothing but spaces equal to "" (empty string). In
the case
of the numeric fields, this works perfectly. However, the char and
varchar field
types seem to insert an empty value, but not a null. I've got the
checkbox for
'keep null values' turned on. How would I go about inserting a null
value into
these fields?
Any help would be greatly appreciated.
Thanks in advance,
~Gary


if( Trim( DTSSource("ColumnSource")) = "") then
DTSDestination("ColumnDestination") = null
end if




Reply With Quote
  #3  
Old   
Gary Helriegel
 
Posts: n/a

Default Re: Flat File Import and Null Values - 08-03-2006 , 04:23 AM



Davide wrote:

Quote:
if( Trim( DTSSource("ColumnSource")) = "") then
DTSDestination("ColumnDestination") = null
end if

I've got something similar (Created a function as I'd be doing this on every
field save 2 or 3). I've listed the code below. I'm not sure what's causing it
to not like to insert an actual null on alpha fields, though.


Function TrimNullIf(SourceString, IfNull)

If trim(SourceString) = null Then
TrimNullIf = IfNull
Else
TrimNullIf = trim(SourceString)
End If

End Function

And it is being called like so:

DTSDestination("S2_Agency") = TrimNullIf(DTSSource("Col002"),null)

--
Posted via a free Usenet account from http://www.teranews.com



Reply With Quote
  #4  
Old   
Davide
 
Posts: n/a

Default Re: Flat File Import and Null Values - 08-03-2006 , 06:14 AM



Hello Gary,

Quote:
Davide wrote:

if( Trim( DTSSource("ColumnSource")) = "") then
DTSDestination("ColumnDestination") = null
end if
I've got something similar (Created a function as I'd be doing this on
every field save 2 or 3). I've listed the code below. I'm not sure
what's causing it to not like to insert an actual null on alpha
fields, though.

Function TrimNullIf(SourceString, IfNull)

If trim(SourceString) = null Then
TrimNullIf = IfNull
Else
TrimNullIf = trim(SourceString)
End If
End Function

And it is being called like so:

DTSDestination("S2_Agency") = TrimNullIf(DTSSource("Col002"),null)


like this one?


Function TrimNullIf(SourceString, IfNull)
If IsNull(SourceString) OR trim(SourceString) = "" Then
TrimNullIf = IfNull
Else
TrimNullIf = trim(SourceString)
End If
End Function




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.