|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 132,
Visits: 600
|
|
I'm trying to replace an existing function with an SSIS package. Rows are exported to a comma delimited flat file for archiving and deleted from the source table. The current method produces a file with data quoted and blank columns not quoted. Ex "data1","data2",,"data4" I set the Text Qualifier on my Flat File Connection Mgr to " But I get this: "data1","data2","","data4" All columns in the Flat File Connection Mgr are strings. I don't normally quote text on an export, but since I'm mimicking another process I thought I'd try and be exact. Can this be done? Thanks all.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 12:23 PM
Points: 5,674,
Visits: 6,117
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 132,
Visits: 600
|
|
I couldn't get that to work. I mean the syntax is good, but I got the same result. Its true that these are 0-length strings. So to make them NULL I changed the select query to: case when ltrim(rtrim(mycol)) = '' then NULL else ltrim(rtrim(mycol)) end as mycol. In the preview I saw the NULL value, but it still got quoted. Seems like the Text Qualifier in the flat file connection manager is overriding everything.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 12:23 PM
Points: 5,674,
Visits: 6,117
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 132,
Visits: 600
|
|
Yea, they are empty string before the derived column transformation and NULL after the derived column transformation.
And the result is all columns quoted.
Screen shots are attached.
In the attached gifs you can see column EdiCarrier is one of the culprits. This columns has data in some rows, but not all. So I changed the query to only select rows where EdiCarrier = '' wondering if the column was NULL for every row, might it make a difference. There was no change in the behavior. I also deleted the flat file connection mgr and recreated it. I've seen it where it seems like a flat file connection definition gets "stuck" after making edits to it.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 8:55 AM
Points: 132,
Visits: 600
|
|
I read elsewhere that since a flat file is a text file, if you use a Text Qualifier it will be applied to every column. So here's what works... remove the Text Qualifier and as a derived column use: mycol !="" ? "\"" + mycol + "\"" : mycol This adds two to the length of every column with data. I have some datetime data types in the table that got converted to char(10) for formatting in the select query and I was failing with a truncation error on them. I could not edit the length in the Derived Column Transformation Editor. So I tried mycol !="" ? DT_STR(<len+2>,1252)("\"" + mycol + "\"") : mycol. It didn't fail, but gave me "10/09/201 in the date columns in the output file. Not sure what I was doing wrong there. So I changed the select query to pad all the columns giving ample space for the max data plus the quotes. Ex: convert(varchar(50),convert(varchar(10),datetimeColumn,101)) as mycol. Learned a little more about SSIS Expression Language today! Thanks for all your time and effort.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 12:46 PM
Points: 1,290,
Visits: 3,860
|
|
Randy Doub (2/20/2013) I read elsewhere that since a flat file is a text file, if you use a Text Qualifier it will be applied to every column. So here's what works... remove the Text Qualifier and as a derived column use: mycol !="" ? "\"" + mycol + "\"" : mycol This adds two to the length of every column with data. I have some datetime data types in the table that got converted to char(10) for formatting in the select query and I was failing with a truncation error on them. I could not edit the length in the Derived Column Transformation Editor. So I tried mycol !="" ? DT_STR(<len+2>,1252)("\"" + mycol + "\"") : mycol. It didn't fail, but gave me "10/09/201 in the date columns in the output file. Not sure what I was doing wrong there. So I changed the select query to pad all the columns giving ample space for the max data plus the quotes. Ex: convert(varchar(50),convert(varchar(10),datetimeColumn,101)) as mycol. Learned a little more about SSIS Expression Language today! Thanks for all your time and effort.
Randy, just watch out for when mycol contains any double quotes, then you have a problem...
MM
|
|
|
|