码迷,mamicode.com
首页 > 其他好文 > 详细

SSIS DataType Conversion

时间:2015-05-26 16:03:24      阅读:1049      评论:0      收藏:0      [点我收藏+]

标签:

SSIS DataType Conversion 将表达式从一种数据类型显式转换为另一种数据类型,转换运算符还可以用作截断运算符。

类型转换的语法是: (type_spec)  expression

示例:

1,将一个数值转换为整数。

(DT_I4) 3.57

2,将整数转换为使用 1252 代码页的字符串。

(DT_STR,1,1252)5

3,将三字符的字符串转换为双字节字符。

(DT_WSTR,3)"Cat"

4,将整数转换为带两位小数的十进制数。

(DT_DECIMAl,2)500

5,将整数转换为带 3 位小数且精度为 7 的数值。

(DT_NUMERIC,7,3)4000

6,将 FirstName 列中的值(定义为 nvarchar 数据类型且长度 50)转换为使用 1252 代码页的字符串。

(DT_STR,50,1252)FirstName

7,将字符串文字“True”转换为布尔值。

(DT_BOOL)"True"

8,将字符串文字转换为 DT_DBDATE。

(DT_DBDATE) "1999-10-11"

9,将字符串文字转换为使用 5 位小数秒的 DT_DBTIME2 数据类型。(对于 DT_DBTIME2 数据类型可以指定 0 到 7 位小数秒。)

(DT_DBTIME2, 5) "16:34:52.12345"

10,将字符串文字转换为使用 4 位小数秒的 DT_DBTIMESTAMP2 数据类型。(对于 DT_DBTIMESTAMP2 数据类型可以指定 0 到 7 位小数秒。)

(DT_DBTIMESTAMP2, 4) "1999-10-11 16:34:52.1234"

11,将字符串文字转换为使用 7 位小数秒的 DT_DBTIMESTAMPOFFSET 数据类型。(对于 DT_DBTIMESTAMPOFFSET 数据类型可以指定 0 到 7 位小数秒。)

(DT_DBTIMESTAMPOFFSET, 7) "1999-10-11 16:34:52.1234567 + 5:35"

12,为某些数据类型转换时需要参数。下表列出了这些数据类型及其参数。

 

数据类型

参数

示例

DT_STR

charcount                  

codepage                  

(DT_STR,30,1252) 将 30 个字节(即 30 个单字符)转换为使用 1252 代码页的 DT_STR 数据类型。

DT_WSTR

Charcount                  

(DT_WSTR,20) 将 20 个字节对(即 20 个 Unicode 字符)转换为 DT_WSTR 数据类型。

DT_BYTES

Bytecount                  

(DT_BYTES,50) 将 50 个字节的数据转换为 DT_BYTES 数据类型。

DT_DECIMAL

Scale                  

(DT_DECIMAL,2) 将数值转换为带 2 位小数的 DT_DECIMAL 数据类型。

DT_NUMERIC

Precision                  

Scale                  

(DT_NUMERIC,10,3) 将数值转换为带 3 位小数且精度为 10 的 DT_NUMERIC 数据类型。

DT_TEXT

Codepage                  

(DT_TEXT,1252) 将值转换为使用 1252 代码页的 DT_TEXT 数据类型。

13,MSDN URL
https://msdn.microsoft.com/zh-cn/library/ms141704(v=sql.100).aspx


附表:SSIS to SQL Server Data Type Translations
 
SSIS Data Type SSIS Expression SQL Server
single-byte signed integer (DT_I1)  
two-byte signed integer (DT_I2) smallint
four-byte signed integer (DT_I4) int
eight-byte signed integer (DT_I8) bigint
single-byte unsigned integer (DT_UI1) tinyint
two-byte unsigned integer (DT_UI2)  
four-byte unsigned integer (DT_UI4)  
eight-byte unsigned integer (DT_UI8)  
float (DT_R4) real
double-precision float (DT_R8) float
string (DT_STR, «length», «code_page») char, varchar
Unicode text stream (DT_WSTR, «length») nchar, nvarchar, sql_variant, xml
date (DT_DATE) date
Boolean (DT_BOOL) bit
numeric (DT_NUMERIC, «precision», «scale») decimal, numeric
decimal (DT_DECIMAL, «scale») decimal
currency (DT_CY) smallmoney, money
unique identifier (DT_GUID) uniqueidentifier
byte stream (DT_BYTES, «length») binary, varbinary, timestamp
database date (DT_DBDATE) date
database time (DT_DBTIME)  
database time with precision (DT_DBTIME2, «scale») time(p)
database timestamp (DT_DBTIMESTAMP) datetime, smalldatetime
database timestamp with precision (DT_DBTIMESTAMP2, «scale») datetime2
database timestamp with timezone (DT_DBTIMESTAMPOFFSET, «scale») datetimeoffset(p)
file timestamp (DT_FILETIME)  
image (DT_IMAGE) image
text stream (DT_TEXT, «code_page») text
Unicode string (DT_NTEXT) ntext

SSIS DataType Conversion

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/4503317.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!