在外部查询错误中转换日期

时间:2015-01-14 14:01:11

标签: sql-server

我有以下查询

select * 
from
    (select 
         ta.SDSKNumber, tc.genericAttribute, tb.genericAttributeValue,
         CONVERT(date,tb.genericAttributeValue,109) AS actualDeliveredDate  
     from 
        dbo.tbl_in_SDSKs as ta 
     inner join 
        dbo.tbl_in_SDSKsGenericAttributes as tb on ta.SDSKNumber = tb.SDSKNumber
     inner join 
        dbo.tbl_gn_GenericAttributes as tc on tb.idGenericAttribute = tc.idGenericAttribute
     where 
        tc.genericAttribute = 'Actual Deliver Date'  
        AND tb.genericAttributeValue <> '') as ta
where 
    ta.actualDeliveredDate BETWEEN  '2014-09-01' AND '2014-12-31 23:59:59'

如果我运行内部查询,我会得到这些结果

SDSKNumber  genericAttribute    genericAttributeValue   actualDeliveredDate
---------------------------------------------------------------------------
37122112    Actual Deliver Date Jan  1 2014 12:00AM     2014-01-01
37762736    Actual Deliver Date Oct 14 2013 12:00AM     2013-10-14
38466008    Actual Deliver Date Nov 25 2013 12:00AM     2013-11-25
41264584    Actual Deliver Date Mar  6 2014 12:00AM     2014-03-06

但是当我运行外部查询来执行比较时

ta.actualDeliveredDate BETWEEN  '2014-09-01' AND '2014-12-31 23:59:59'

我收到错误:

  

从字符串转换日期和/或时间时转换失败。

如果actualDeliveredDate field已经转换为日期,为什么会出现此错误?

我使用的是SQL Server 2008R2。

非常感谢。

0 个答案:

没有答案