4

我得到错误,

将数据类型 varchar 转换为日期时出错。

从这个表达式

(DT_STR,30,1252)@[User::ToDate]

DO NET 源 [40]:执行提供的 SQL 命令时发生错误:“EXEC [dbo.StoredProcedure] @ToDate = '01-maj-2018'

错误:导入时出现 0xC004706B(请参阅表达式!),SSIS.Pipeline:“ADO NET 源”验证失败并返回验证状态“VS_ISBROKEN”。

@ToDate = '01-maj-2018'

我怎样才能改变它,所以我的@ToDate意志01-may-2018不是01-maj-2018

我试图搜索并且有很多类似的问题,但没有一个关于这个特定错误的问题。为什么它甚至让我的字符串有maj

4

3 回答 3

0

不确切知道错误,但我认为这可能是由于 SQL Server 排序规则,请尝试检查您的服务器排序规则。或者可能正在探索排序规则可能会对您有所帮助。

排序规则

于 2019-02-20T11:31:59.583 回答
0

您的包裹的 LocaleID 似乎不同于 1033(英语-美国)。

该值可以在包级别进行调整,因此所有底层任务都将继承它。

如果值是在 SQL Server 端生成的,还可以与 SQL Server 登录的语言设置相关

检查什么会影响 SSIS 中的日期区域设置的相关问题:SSIS 2012 日期格式 dmy vs mdy

于 2019-02-20T12:49:01.317 回答
0

我同意@AlexanderVolok,看起来包的 LocalID 与英语不同,或者在操作系统区域设置中选择的日期时间文化信息不同。

(1) 使用条件更改月份名称?:

如果您可以更改这些属性,那么它可能会解决问题,否则您可以在数据流任务之前添加一个表达式任务,该任务使用条件运算符将日期转换为具有不同格式的字符串? :,例如(假设您正在处理波兰月份名称) :

@[User::NewDataString] = 
LEFT((DT_WSTR,50)@[User::ToDate],2) + "-" +
(SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "maj" ? "may" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "stycz" ? "Jan" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "lut" ? "feb" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "mar" ? "mar" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "maj" ? "may" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "czerw" ? "jun" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "lip" ? "jul" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "sierp" ? "aug" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "wrzes" ? "sep" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "pazdzier" ? "oct" : 
SUBSTRING((DT_WSTR,50)@[User::ToDate], FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) + 1,  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",2) -  FINDSTRING((DT_WSTR,50)@[User::ToDate],"-",1) - 1)  == "listopad" ? "nov" : "dec" )
+ "-" + RIGHT((DT_WSTR,50)@[User::ToDate],4)

然后你应该将新变量作为参数传递。

(2) 更改数据格式为 yyyy-MM-dd

您还可以使用Expression Task将月份转换为数值,例如:

@[User::NewDateString] = 
RIGHT((DT_WSTR,50)@[User::ToDate],4) + "-" +
RIGHT("0" + (DT_WSTR,50)DATEPART("mm", @[User::ToDate]),2) + "-" + 
LEFT((DT_WSTR,50)@[User::ToDate],2)

参考

于 2019-02-20T21:53:18.323 回答