如何解决SQL中的datetime转换错误 [英] How to solve datetime conversion error in SQL

查看:310
本文介绍了如何解决SQL中的datetime转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我想从开始和结束日期之间收集报告。我在sql server中出错了..



我尝试了所有日期格式但没有使用相同的错误重复....

错误:



从字符串转换日期和/或时间时转换失败。



我有什么试过:



从Vw_WorkSheetQty选择RetDate,ItemName,cast(MatQty为数字(10,2))totalcount

'2016年2月2日'和'26 / 2016/2016'之间的RetDate





数据类型是datetime

Dear Friends,

I want to take report from between start and end date. I got an error in sql server..

I tried all dateformats but no use same errors repeating....
Error:

Conversion failed when converting date and/or time from character string.

What I have tried:

select RetDate, ItemName, cast(MatQty as numeric(10, 2)) totalcount
from Vw_WorkSheetQty where RetDate between '01/02/2016' and '26/02/2016'


datatype is datetime

推荐答案

什么是2016年2月26日?第二个月的第26个月?第26个月的第2个?第26年第二个月的第2016天?你可能看起来很明显,但记得电脑只知道它被告知了什么。如果你真的必须使用字符串作为日期,那么使用明确的格式。



What is 26/2/2016? 26th of the second month? 2nd of the 26th month? 2016th day of the second month of the 26th year? It might seem obvious to you but remember the computer only knows what it is told. If you really must use strings as dates then use unambiguous formats.

between '1 feb 2016' and '26 feb 2016'


这篇关于如何解决SQL中的datetime转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆