How to achieve TRY_CONVERT functionality in SSIS?

南楼画角 提交于 2020-01-04 02:03:14

问题


In SSIS package I have derived column in which I want to format phone like below:

CASE
    WHEN TRY_CONVERT(BIGINT, phone) IS NULL THEN
        NULL
    ELSE
        phone
END

How can I use the SSIS expression to achieve same result as above?


回答1:


Derived Column

You have to use the following expression:

(DT_I8)[Phone] == (DT_I8)[Phone] ? [Phone] : NULL(DT_WSTR,50)

Note that you have to replace (DT_WSTR,50) with the data type of column [Phone]. Click here for more information

And in the derived column error output change the on error option to Ignore Failure

Script Component

You can also achieve this using a script component:

  1. Add a script component to the data flow task
  2. Select [Phone] as Input Column
  3. Create a new Output Column of the same type of [Phone] example [outPhone]
  4. Use a similar code

    if(!Row.Phone_IsNull && !String.IsNullOrEmpty(Row.Phone) && Int64.TryParse(Row.Phone, out long number)){
    
        Row.OutPhone = Row.Phone;
    
    }else{
    
        Row.OutPhone_IsNull = true;
    
    }
    


来源:https://stackoverflow.com/questions/55482719/how-to-achieve-try-convert-functionality-in-ssis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!