SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to Handle NULL Values Loaded by SSIS from Excel Files


How to Handle NULL Values Loaded by SSIS from Excel Files

Author
Message
rajgadiraju
rajgadiraju
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 28
Another way is to add a "Derived Column Transform" and use the expression "?" with a default value that replaces null.

Example: ISNULL([testColumn])?0:[testColumn]

Raj
$JW
$JW
SSChasing Mays
SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)

Group: General Forum Members
Points: 622 Visits: 94
How about this simple solution:

http://blog.tylerholmes.com/2007/12/walkthrough-connecting-to-excel-2007.html

Tongue
Peter Schott
Peter Schott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1475 Visits: 1918
Raj,
If you add that expression, you will indeed not have a NULL in the column, but that doesn't help the case where there was actual data in the column that was lost because the JET driver looked at the column and treated it as a FLOAT instead of a CHAR(255). The best example I have for this is Zip+4 codes mixed with Zip codes in a single column. Excel will read the column, see that the majority are FLOAT and will treat anything with a hyphen as a NULL for purposes of import because it's not a FLOAT. That defeats the purpose.

JW,
That solution looks okay, but as one person commenting on it noted, it forces everything to a char(255) and you lose any Memo data that might have been stored. If one of your columns is > 255 characters, you lose the data. You also then have to deal with everything that is now being treated as a char(255) and any odd conversions that happen as a result. That in itself shouldn't be too bad, but it is a pain. It's also kind of frustrating because you can't set that option when using the Wizard. You need to code for it. Tongue


As noted in one of my earlier posts, I deal with this when receiving files from customers that have multiple sheets (making it impractical to try to export and choose a good delimiter), a mixture of data-types, and usually with some Note/Memo data. That leaves me with a lot of pain points when trying to load data directly from Excel. And there are a lot of workarounds, but hopefully people will be aware that there are definitely some areas to watch for when importing Excel using SSIS.
niall.baird
niall.baird
Old Hand
Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)

Group: General Forum Members
Points: 352 Visits: 484
I found the answer - use a conditional split - work out which column can never be null for a valid row, divert all of the rows that do NOT fit that condition in to the remainder of the data flow

Easy....innit....dunno why it stumped me for so long!
davidgr144
davidgr144
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 27
I'm having a similar problem to this but it is localised to my machine only. My colleague wrote a package to import an Excel spreadsheet in SQL Server. It works perfectly on his machine but when we transferred the package/solution in its entirety to my machine, the behaviour described in this forum appeared on mine. Does anyone have any ideas why this might be the case. We have the same software version and all drivers on both our computers are the same.
Peter Schott
Peter Schott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1475 Visits: 1918
Perhaps he has the registry settings for IMEX or similar set differently on his machine? If you can be more specific with the issues, that might help some. My best guess is that your colleague's registry settings are different than yours.
davidgr144
davidgr144
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 27
First of all, regarding registry settings, noone in our office can edit registry settings, at least through regedit as it has been disabled for use across the organisation.

As far as more information:

The column I refer to has dates in. There are around 1000 rows of data. The first three rows in the particular column are empty. Then there are a few dates and the pattern sort of repeats itself like that. When the data is previewed in SSIS, the first three rows show as empty for that column but every row with a valid date in shows as "NULL".
niall.baird
niall.baird
Old Hand
Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)Old Hand (352 reputation)

Group: General Forum Members
Points: 352 Visits: 484
Use a derived column to convert the datestring to the format yyyy-mm-dd
RIGHT(thedate,4) + "-" + SUBSTRING(thedate,4,2) + "-" + SUBSTRING(thedate,1,2)

as a unicode string (DT_WSTR) then convert that (data conversion) do a date (dt_date). This is what works for me.
Peter Schott
Peter Schott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1475 Visits: 1918
Sounds very much like the registry settings may have been edited - perhaps with a support ticket or similar. That sounds suspiciously like the option to read all rows in a column to determine its type. Otherwise, your package could be treating that column as just about any other type and running into issues w/ conversion.

I assume that you've verified for all of the non-NULL columns that the data contains a valid date and not something that's almost a date. Is it possible that it's trying to read in some slightly different format for the date and choking on that? Perhaps trying to read dd-mm-yyyy instead of mm-dd-yyyy or yyyymmdd?

Without knowing too much more about the file(s), is it also possible that the files that have run successfully have had fully populated date columns? I know that once you release a spec into the wild you don't really know what you'll get back.
Sune de Vos
Sune de Vos
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 118
Thanks thejackfy :-) Great workaround!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search