SQL Server SSIS replace column value based on another columns

hgc7kmma  于 2023-11-16  发布在  其他
关注(0)|答案(1)|浏览(104)

I have a table that among other fields, has the following.

I has an ETL on SSIS package that reads from this table these two fields and many others. How can I do so that before writing on the final table, for every row where Cod_Cliente is 1111111 I replace the Cliente value to "Trial"?

My initial thought was to create a derived column tool to create a new column with logic to just copy values unless I have the mentioned Code, in which case I add the "Trial" text, but I was wondering if there is a more efficient way to update the value on the go.

lh80um4z

lh80um4z1#

Knowing only what you've shared, my approach would be to fix the data as you query it from the source table

SELECT col1
, Cod_Cliente
, CASE WHEN Cod_Cliente = 1111111 THEN 'Trial' ELSE Cod END As Cod
FROM dbo.MyTable

That way, everything is set before it hits the pipeline.

If you want to go with a derived column, I prefer a new column over updating existing as it makes it easier for me to debug. Either way, the expression would be something like (case sensitive column names) assuming the data type for Cod_Cliente is integer like.

([Cod_Cliente] == 1111111) ? "Trial" : [Cod]

相关问题