0
UPDATE tblCampaigns SET startDate = '4 December, 2010', endDate = '14 January, 2011' WHERE ID = 147
UPDATE tblCampaigns SET startDate = '24 December, 2010', endDate = '17 Febuary, 2011' WHERE parentID = 147 and campaignName = 'regerg'

Microsoft OLE DB Provider for SQL Server error '80040e07' 

Syntax error converting datetime from character string. 

/bb/campaignManager/index.asp, line 147 

这些在日期为 2010 年时有效,但一旦将 2011 年放入其中,它就会出错,有什么想法吗?应该是格式不对吧?

4

2 回答 2

4

是“二月”,不是“二月”

于 2010-12-22T11:10:45.580 回答
0

我永远不会那样做:如果数据库中的默认日期格式发生变化,那么你就完蛋了。相反,始终将字符串显式转换为日期,以便您保留控制权:

UPDATE tblCampaigns SET startDate = convert(datetime, '20101204', 112)

http://msdn.microsoft.com/en-us/library/aa226054(v=SQL.80).aspx

于 2010-12-22T11:19:18.180 回答