尝试在两个日期之间执行 sql 语句时出错
SQL:
dim sql
sSql = "SELECT * FROM [dbo].[table] WHERE [sent] = 1 and datesent between '" & dStartDate & "' and '" & dFinishDate & "'"
response.write(sSql)
set oRs = oConn.execute(sSql)
当我在 sql server 2008 中执行此 sql 时,它工作正常。 但是,当我在应用程序中执行它时,我收到错误:
Microsoft OLE DB Provider for SQL Server error '80040e07'
The conversion of a char data type to a datetime data type resulted
in an out-of-range datetime value.
我必须在应用程序中做一些不同的事情吗?谢谢
The SQL:
dim sql
sSql = "SELECT * FROM [dbo].[table] WHERE [sent] = 1 and datesent between '" & dStartDate & "' and '" & dFinishDate & "'"
response.write(sSql)
set oRs = oConn.execute(sSql)
When i execute this sql in sql server 2008 it works fine.
However, when i execute it within my application i get error:
Microsoft OLE DB Provider for SQL Server error '80040e07'
The conversion of a char data type to a datetime data type resulted
in an out-of-range datetime value.
Is there something different i have to do in the application? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过使用 ISO 格式的日期吗?
(严格来说,sql server 的ISO 8601 日期是
yyyy-mm-ddThh:mm :ss[.mmm]
)旁注:当输出到文本(或有文字)时,始终使用 ISO 格式日期;这样它们就可以在所有系统上明确地读取)。
SQL Server ISO 8601 格式日期
< a href="http://msdn.microsoft.com/en-us/library/ms190977(v=sql.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190977(v=sql.90).aspx
Have you tried using ISO format dates?
(Strictly speaking an ISO 8601 date for sql server is
yyyy-mm-ddThh:mm:ss[.mmm]
)Side Note: always use ISO format dates when you output to text (or have literals); that way they can be read unambiguously on all systems).
SQL Server ISO 8601 Format Dates
http://msdn.microsoft.com/en-us/library/ms190977(v=sql.90).aspx
OR
您的列
datesent
不是DATETIME
数据类型OR
Your column
datesent
is notDATETIME
datatype检查您的日期时间设置。
您可以使用以下命令显示当前设置:
Check your datetime setting.
You can display the current setting with:
您应该始终对日期使用 ISO 格式“YYYYMMDD”,因为无论本地化设置如何,SQL Server 始终会正确解析该格式。
You should always use the ISO-formats 'YYYYMMDD' for your dates, as this will always be parsed correctly by SQL Server, regardless of localization setting.