我有一个SSIS包来自自定义表的导出数据,该表包含一个日期时间戳列(yyyy-mm-dd 00:00:00:000)。创建文本文件时,它会删除最后一个' 0'。我将数据类型更改为数据库时间戳[DT_DBTIMESTAMP] IN ssis但它不起作用。
答案 0 :(得分:0)
对我来说很好,你在做什么?如果您将数据类型引入不是字符串的任何内容,则可以修剪所有尾随零,因为写入100.00与100.000000000的值相同为100.如果尾随零是重要的,则必须将其强制转换到字符串类型以保留这些值。
我有一行作为日期时间数据类型以及使用ISO格式的字符串发送到数据流
SELECT
D.Val AS ValueAsDateTime
, CONVERT(char(24), D.Val, 121) AS ValueAsString
FROM
(
VALUES
( CAST('2015-03-17T23:59:59.997' AS datetime))
) D (Val);
我定义了一个CSV,它分别使用DT_DBTIMESTAMP和DT_STR作为类型。这是存储在我的文件中的内容
ValueAsDateTime,ValueAsString
2015-03-17 23:59:59.997000000,2015-03-17 23:59:59.997
恐惧简单包
如果您安装了BIDS Helper,以下Biml将生成我的复制包。
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<!-- Create a basic flat file source definition -->
<FileFormats>
<FlatFileFormat
Name="FFF"
CodePage="1252"
RowDelimiter="CRLF"
IsUnicode="false"
FlatFileType="Delimited"
ColumnNamesInFirstDataRow="true"
>
<Columns>
<Column
Name="ValueAsDateTime"
DataType="DateTime"
Delimiter=","
ColumnType="Delimited"
/>
<Column
Name="ValueAsString"
DataType="AnsiString"
Delimiter="CRLF"
InputLength="20"
MaximumWidth="20"
Length="20"
CodePage="1252"
ColumnType="Delimited"
/>
</Columns>
</FlatFileFormat>
</FileFormats>
<!-- Create a connection that uses the flat file format defined above-->
<Connections>
<FlatFileConnection
Name="CM_FF"
FileFormat="FFF"
FilePath="C:\ssisdata\29520836.txt"
DelayValidation="true"
/>
<OleDbConnection
Name="CM_OLE"
ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;"
/>
</Connections>
<!-- Create a package to illustrate how to apply an expression on the Connection Manager -->
<Packages>
<Package
Name="so_29520836"
ConstraintMode="Linear"
>
<!-- Create a single variable that points to the current file -->
<Variables>
<Variable DataType="String" Name="QuerySource">SELECT D.Val As ValueAsDateTime, CONVERT(char(24), D.Val, 121) AS ValueAsString FROM (VALUES(CAST('2015-03-17T23:59:59.997' AS datetime)))D(Val);</Variable>
</Variables>
<!-- Add a foreach file enumerator. Use the above -->
<Tasks>
<Dataflow Name="DFT Import file" DelayValidation="true">
<Transformations>
<OleDbSource ConnectionName="CM_OLE" Name="OLE_SRC Query">
<VariableInput VariableName="User.QuerySource" />
</OleDbSource>
<FlatFileDestination ConnectionName="CM_FF" Name="FF_DST"></FlatFileDestination>
</Transformations>
</Dataflow>
</Tasks>
</Package>
</Packages>
</Biml>