本文介绍了将varchar数据类型转换为datetime数据类型导致TSQL中的值超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在我的T-SQL中选择日期时间似乎有错误 select t.F47 ,t.F53,t.F40,t.F162,t.F163, N'10'as kostenart,t.F39,t.F2,t.F5, convert(nvarchar,cast( t9)作为日期时间),112), t.PARID,20170928135800作为exportzeitstempel 从 T_TRANS6作为t 其中 t.F20 = N'Erledigt' 和t.F9 convert(datetime,'01 .09.2017 00:00:00',104) 错误消息是德语并说:我试图将其翻译为:我真的不知道我是怎么做到的,谢谢大家的帮助解决方案您的问题是由 cast(t.F9作为日期时间)触发的。 请执行以下操作: SELECT getdate(); 以获得隐式的日期时间到字符串转换格式。 警告:隐式转换格式是在实例级别设置的。服务器之间可能会有所不同,即使在同一个公司中也是如此... 这将为您提供类似 dd.MM.yyyy HH:mm:ss 或 yyyy-MM-dd HH:mm:ss 或... 给定格式为 一个格式格式错误的单个TRANS6.F9会引发此错误,这是TRANS6表记录的所有F9的预期值,必需。 。因此,分析您的F9数据,找到相关的行,清理它们并重试... 注意:CONVERT(NVARCHAR(8),getdate(),112)得到一个像 YYYYMMDD 这样的字符串(例如:'20170928')女巫是唯一可排序的日期字符串格式... 编辑:F9 ='2016.10.30'并且隐式转换期望'2016-10-30'!! 尝试一下: 选择 t.F47,t.F53,t.F40,t.F162,t.F163, N'10'作为kostenart, t.F39,t.F2,t.F5, convert(nvarchar,convert(datetime,t.F9,102),112), t.PARID,20170928135800 as exportzeitstempel from T_TRANS6为t ,其中 t.F20 = N'Erledigt'并且t.F9 可以吗? In my T-SQL select there appears to be an error with my datetimeselect t.F47, t.F53, t.F40, t.F162, t.F163, N'10' as kostenart, t.F39, t.F2, t.F5, convert(nvarchar, cast(t.F9 as datetime), 112), t.PARID, 20170928135800 as exportzeitstempelfrom T_TRANS6 as twhere t.F20 = N'Erledigt' and t.F9 < convert(datetime, '01.09.2017 00:00:00', 104)The error message is German and it says: I tried to translate this to: I really don't know how I did from so thanks for any help guys 解决方案 Your problem is triggered by cast(t.F9 as datetime).Please do : SELECT getdate(); to get the implicit "datetime to string" convertion format.WARNING : Implicit convertion format are set at the instance level. It can differ from a server to another, even in the same compagny...This will gives you someting like dd.MM.yyyy HH:mm:ss or yyyy-MM-dd HH:mm:ss or ...The given format is the one expected and required for all F9 of TRANS6 table records!!A single TRANS6.F9 with a wrong formating patern will raise this ERROR. So analyse your F9 data, find the concerned rows, clean them and retry...NOTE : CONVERT(NVARCHAR(8), getdate(),112) get a string like YYYYMMDD (Ex : '20170928') witch is the only sortable string format of dates...EDIT : F9 = '2016.10.30' and Implicit convertion expect '2016-10-30' !!Try this :select t.F47, t.F53, t.F40, t.F162, t.F163, N'10' as kostenart, t.F39, t.F2, t.F5, convert(nvarchar, convert(datetime,t.F9,102), 112), t.PARID, 20170928135800 as exportzeitstempelfrom T_TRANS6 as twhere t.F20 = N'Erledigt' and t.F9 < convert(datetime, '01.09.2017 00:00:00', 104)Does it works? 这篇关于将varchar数据类型转换为datetime数据类型导致TSQL中的值超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-12 09:21