日期:2014-05-17  浏览次数:21128 次

ASP运行错误
PC_DATE 为DATE类型,
错误信息为:“Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e07' 

[Microsoft][ODBC SQL Server Driver][SQL Server]運算元類型衝突: date 與 int 不相容 

/index.asp,行 69


错误语句为“
sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg where pc.pc_sort=bg.pc_sort and pc.pc_date="&dateAdd("d",2-weekday(date),date())&" ORDER BY pc_date" ”

有知道的兄弟速帮忙解决!


------解决方案--------------------
sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg where pc.pc_sort=bg.pc_sort and pc.pc_date="&dateAdd("d",2-weekday(date),date())&" ORDER BY pc_date"
mssql不需要加引号
------解决方案--------------------
sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg where pc.pc_sort=bg.pc_sort and pc.pc_date = '" & dateAdd("d",2-weekday(date),date()) & "' ORDER BY pc_date"

因为你 dateAdd("d",2-weekday(date),date()) 计算结果是:2012-xx-xx 输出SQL后,SQL认为这是2012减xx减xx, 即为一个int.

因此,你需要用引号引起数据,由SQL自动转换为date.
------解决方案--------------------
探讨

数据库为Microsoft SQL Server 2008


sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg where pc.pc_sort=bg.pc_s……

------解决方案--------------------
探讨

引用:

数据库为Microsoft SQL Server 2008


sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg……

------解决方案--------------------
你应该使用SQL里面的函数。
例子

sql = "SELECT pc.pc_department,pc.pc_sort,pc.pc_time,pc.pc_time1,pc.pc_time,pc.pc_title,bg.pc_style FROM gspaicheng as pc, gssort_bg as bg where pc.pc_sort=bg.pc_sort and DATEDIFF(d, pc.pc_date,getDate()) = " & (2-weekday(date)) & " ORDER BY pc_date"

http://msdn.microsoft.com/zh-cn/library/ms186819%28v=sql.100%29.aspx
------解决方案--------------------


数据表字段类型是字符型等

参数需要 '' 如:'"&str&"'

数据表字段类型是数字型的


"&str&"

时间性

#"&str&"#

...