SQL datetime会话错误 [英] SQL datetime convetion error

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

问题描述

亲爱的,

我希望传递日期和时间在哪里我想要修复日和修复时间但我的年和月将采取当前月和年份。当前月份是三月,我的查询是从TableName中选择*,其中Dateandtime ='2014-03-01 00:00:00'



为此我正在尝试Where Dateandtime = Convert(Datetime,datepart(yyyy,Getdate()+' - '+ datepart(mm,Getdate()+' - '+'01 00 :00:00'),120)但是以字符串格式转换时出现问题

请做好。

解决方案

试试这个:

其中Dateandtime = DATEADD(月,月(getdate()) -  1,DATEADD(年,年(getdate()) -  1900, 0))


Dear,
I want pass dateandtime in where condtion in which i want Fix Day and Fix Time but My Year and Month will Taken Current Month and year Eg. Current Month is March my query is Select * from TableName where Dateandtime = '2014-03-01 00:00:00'

For this i am trying Where Dateandtime = Convert(Datetime, datepart(yyyy,Getdate()+'-'+datepart(mm,Getdate()+'-'+'01 00:00:00'),120) but there is problem in converting in string format
please do needful.

解决方案

Try this:

where Dateandtime = DATEADD(month,month(getdate())-1,DATEADD(year,year(getdate())-1900,0))


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

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