我得到了错误
将数据类型varchar转换为日期时出错。
根据此表达式
(DT_STR,30,1252)@[User::ToDate]
DO NET源[40]:执行提供的SQL命令时发生错误:“ EXEC [dbo.StoredProcedure] @ToDate = '01 -maj-2018'
错误:导入时为0xC004706B(请参见表达式!),SSIS。管道:“ ADO NET Source”验证失败并返回了验证状态“ VS_ISBROKEN”。
@ToDate = '01-maj-2018'
如何更改它,以使我的@ToDate
是01-may-2018
而不是01-maj-2018
?
我尝试搜索,但有很多类似的问题,但是没有一个关于此特定错误的问题。为何它甚至使我的字符串带有maj
?
答案 0 :(得分:1)
我同意@AlexanderVolok,看起来该程序包的LocalID与英语不同,或者在“操作系统区域设置”中选择的日期时间区域性信息不同。
如果您可以更改这些属性,则可以解决此问题,否则您可以在数据流任务之前添加一个表达式任务,该表达式可以使用条件运算符{{将日期转换为具有不同格式的字符串1}},例如(假设您正在处理波兰月份的名称):
? :
然后您应该将新变量作为参数传递。
您还可以使用 Expression Task (表达式任务)将月份转换为数字值,例如:
@[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)
参考
答案 1 :(得分:0)
虽然不完全了解错误,但我认为可能是由于SQL Server排序规则所致,请尝试检查什么是服务器排序规则。或正在探索排序规则可能会对您有所帮助。
答案 2 :(得分:0)
您的软件包中的LocaleID似乎不同于1033(英语-美国)。
此值可以在程序包级别调整,因此所有基础任务都将继承它。
如果在SQL Server端生成值,也可以与SQL Server登录名的语言设置相关
有关检查哪些因素会影响SSIS中的日期区域设置的相关问题:SSIS 2012 date formats dmy vs mdy