SSIS Derived Column - Is there a good way to trim 400+ columns? -
i have import fixed width flat file , has 486 columns. each 1 needs trimmed before arriving database. know derived column allows me 1 @ time, there way mass rtrim(ltrim( on columns?
two ways (both biml ways assumed you've gathered metadata column names):
1 - script
two ways here also: inputbuffer, or biml row. function inputbuffer provided , i'm sure can create own row.
public class scriptmain : usercomponent { private pipelinebuffer inputbuffer; public override void preexecute() { base.preexecute(); } public override void postexecute() { base.postexecute(); } public override void processinput(int inputid, microsoft.sqlserver.dts.pipeline.pipelinebuffer buffer) { // need access pipelinebuffer isn't exposed in processinputrow inputbuffer = buffer; base.processinput(inputid, buffer); } public override void input0_processinputrow(input0buffer row) { stripleadingtrailingwhitespacebyinputbuffer(inputbuffer); // biml <# foreach (var column in table.columns) { var colname = column.name.tostring().replace("_",""); #> row.<#= colname #> = stripleadingtrailingwhitespacebystring(row.<#= colname #>); <# } } #> } public void stripleadingtrailingwhitespacebyinputbuffer(microsoft.sqlserver.dts.pipeline.pipelinebuffer inputbuffer) { (int = 0; < inputbuffer.columncount; ++i) { if (inputbuffer[i] != null) inputbuffer[i] = inputbuffer[i].tostring().trim(); } } }
2 - derived column biml
foreach (var column in table.columns) { var colname = column.name; #> <derivedcolumns name="(dco) stripwhitespace"> <columns> <column name="derive_<#= colname #>" datatype="ansistring" length="255">stripwhitespace(<#= colname #>)</column> </columns> </derivedcolumns> <# } #>
Comments
Post a Comment