Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

data from flat file Expand / Collapse
Author
Message
Posted Monday, April 30, 2012 4:51 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, July 29, 2012 2:10 PM
Points: 197, Visits: 437
I am trying to load a flat file using SSIS. The data in the flat file is something like this

id, name, status
1, Jassy,
2,, abcd
3, v'dejr, dkfal'sdfh

when I loaded then to the SQL Server, I am getting blank spots on the places where there is no data.

1 Jassy
2 abcd
3 v'dejr dkfal'sdfh

I want null instead, what could be done in the downstream to get it done. There are 28 columns in the actual file and I am trying to avoid update query after I load data.

Thanks


  Post Attachments 
Capture.PNG (6 views, 2.82 KB)
Post #1292873
Posted Monday, April 30, 2012 5:30 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, May 18, 2013 10:09 PM
Points: 5,658, Visits: 6,100
Use a derived column that will check for blank spaces and insert the null version of the datatype into the column if that happens.

Basically, for each column, you'll do something like this as the expression (assuming it's an INT):
LTRIM(RTRIM( Column1)) == "" ? NULL(DT_UI4) : Column1

Use that as a replace columna and it'll include NULLs into the stream. For the source file to actually recognize NULL, they'd have to use the particular ANSI character that is considered it (I forget offhand) which is an unreadable character.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1292880
Posted Wednesday, May 02, 2012 12:14 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 11:10 AM
Points: 740, Visits: 785
Evil Kraig F (4/30/2012)

Basically, for each column, you'll do something like this as the expression (assuming it's an INT):
LTRIM(RTRIM( Column1)) == "" ? NULL(DT_UI4) : Column1


What Evil Kraig says is spot on; one little nitpick, SSIS expressions has a TRIM() function that you can use to replace the LTRIM(RTRIM()). Something like:

TRIM(Column1)) == "" ? NULL(DT_UI4) : Column1
Post #1294093
Posted Thursday, May 03, 2012 7:32 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:49 AM
Points: 2,672, Visits: 2,417
One other thing you can look at, althought I have not tested it for this purpose. In the flat file source editor on the connection manager tab there is a checkbox for "Retain null values from the source as null values in the data flow."
Post #1294594
Posted Friday, May 11, 2012 9:51 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 10:11 AM
Points: 48, Visits: 269
That idea by Dan should work.
Post #1298721
Posted Wednesday, June 06, 2012 5:14 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, February 19, 2013 7:10 AM
Points: 15, Visits: 53
I agree.. Use "Retain null values from the source as null values in the data flow" in flat file connection manager.
Post #1311753
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse