Replace Empty Strings in CSV Flat File with Derived Colum Task

  • I was having some trouble modifying a string column of a CSV file when it had no value before it was inserted into an int field of an SQL Server 2005 table.

    I initially tried by using a Derived Column with Replace(Age,"","0) which didn't work. Using Data Viewers before and after the Derived Column I could see that the value was never changing (empty in both cases).

    I got around this by setting the Flat File Source to retain null values and then modifying my Derived Column to use ISNULL(Age)?"0":Age.

    Just out of curiosity, how should I have originally gone about it without setting the Flat File Source to retain null values? What was wrong with my Replace command? How do I refer to an empty value in a CSV file?

  • I would say that retaining the nulls is the correct handling in this case. That's what the feature is for.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I would agree with GSquared. Especially in this case because an empty value for age does not equate to an age of 0 so Null would be, in my opinion, the best option.

  • Thanks for the help guys, I appreciate it. I'll stick with the null value method.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply