Quantcast
Viewing all articles
Browse latest Browse all 11

re: SSIS: Checking for IsNumeric()

Since this excellent blog has helped me loads to get to grips with SSIS, I thought I would give my ten pence worth.

I was really frustrated with this - and was determined to stick with using a derived column component (I'd already got through mapping 40 odd fields and didnt want to start again using the script component!).

Anyway, I found a hack to get around this issue.

IF NOT NULL(Col) AND ISNUMERIC(Col) THEN

   Result = cLng(Col)

ELSE

   Result = 0

END IF

in DTS

equates to:

Result = !ISNULL([Col]) && ((DT_STR,20,1252) [Col] == ((DT_STR,20,1252) (DT_I4) [Col] )) ? (DT_I4) [Col] : 0

All I do convert Col to an int, then back to a string - and compare it to the original string value.

If they are the same then it's a numeric field.

Also, I believe that because I am checking for null before this happens, the IF statement will jump out when a null is found, stopping the cast to an int from failing.

Seems to work fine for me - hope it helps the rest of you!


Viewing all articles
Browse latest Browse all 11

Trending Articles