SQL:超出范围值
下面的查询给出了此错误SQL:超出范围值,sql,sql-server,Sql,Sql Server,下面的查询给出了此错误 The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value. 该字段的时间日期在数据库中类似于2012年11月13日的英国格式 任何人都知道如何解决这个问题 SELECT PRODID, ITEMDES, QTY, StockCode,shipName, shipCompany, shipAddress
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
该字段的时间日期在数据库中类似于2012年11月13日的英国格式
任何人都知道如何解决这个问题
SELECT
PRODID, ITEMDES, QTY, StockCode,shipName, shipCompany, shipAddress1, shipAddress2, shipAddress3,shipPostCode,shipcity,shipCountry,shipCounty,customerMessage
FROM orderedItems oi
left join orders o on oi.order_id = o.order_id
where( CONVERT(nvarchar(30),timedate,120) >=
<cfqueryparam cfsqltype="cf_sql_date" value="#LSDateFormat(form.fromDate, "yyyy-mm-dd")# 00:00:00">
AND CONVERT(nvarchar(30),timedate,120) <=
<cfqueryparam cfsqltype="cf_sql_date" value="#LSDateFormat(FORM.toDate, "yyyy-mm-dd")# 23:59:59">
)
Group by PRODID,ITEMDES,QTY, StockCode,shipName, shipCompany, shipAddress1, shipAddress2, shipAddress3,shipPostCode,shipcity,shipCountry,shipCounty,customerMessage
ORDER BY PRODID
选择
PRODID、ITEMDES、数量、库存代码、shipName、shipCompany、shipAddress1、shipAddress2、shipAddress3、shipPostCode、shipcity、shipCountry、shipCounty、customerMessage
来自orderedItems oi
oi.order\U id=o.order\U id上的左连接订单o
其中(CONVERT(nvarchar(30),timedate,120)>=
和CONVERT(nvarchar(30),timedate,120)我认为sql server可能会将您的日期解释为美国格式,即mm/dd/YYYY
,显然没有第13个月,因此会出现超出范围的错误
您可能更适合使用适当的字段类型保存日期。“任何人都知道如何解决此问题。”而是store datetimes.db是在我之前构建的,出于未知原因,它被存储为varchar。您在timedate
上有一个值,不能转换为DATETIME
,至少不能转换为您指定的格式。很可能是31/02/2012
或其他格式的版本:05/15/2012
不管怎样,我可以在不把所有事情弄糟的情况下更改类型?@Spike:这取决于这个表的生产效率。但一般来说,最好先存储日期,而不是在转换时乱来。