超出范围的SQL错误

时间:2011-03-04 14:31:43

标签: sql sql-server datetime

我有SQL这样的

SELECT  B.HESAP_NO, A.TEKLIF_NO1 + '/' + A.TEKLIF_NO2 AS 'TEKLIF',
B.MUS_K_ISIM, CONVERT(VARCHAR(10),A.ISL_TAR,103) AS 'TARIH',
ISNULL(CAST(A.ODENEN_ANAPARA AS FLOAT),0)+ISNULL(CAST(A.FAIZ AS FLOAT),0)+
    ISNULL(CAST(A.BSMV AS FLOAT),0)+ISNULL(CAST(A.GECIKME_FAIZ AS FLOAT),0)+
    ISNULL(CAST(A.GECIKME_BSMV AS FLOAT),0) AS 'YATAN', 
    (CASE WHEN B.DOVIZ_KOD = 21 THEN 'EUR' WHEN B.DOVIZ_KOD = 2 THEN 'USD' WHEN B.DOVIZ_KOD = 1 THEN 'TL' END) AS 'KUR',
    D.AVUKAT, CONVERT(VARCHAR(10),C.ICRA_TAR,103) AS 'İCRA TARİHİ', CONVERT(VARCHAR(10),C.HACIZ_TAR,103) AS 'HACİZ TARİHİ'
FROM YAZ..MARDATA.BIR_TAHSIL A, YAZ..MARDATA.S_TEKLIF B, TAKIP C, AVUKAT D, P_TAKIP_SR E
WHERE A.TEKLIF_NO1 = B.TEKLIF_NO1
AND A.TEKLIF_NO2 = B.TEKLIF_NO2
AND B.HESAP_NO = D.HESAP
AND D.HESAP = A.HESAP_NO
AND C.T_HESAP_NO = A.HESAP_NO
AND C.T_SRM = E.T_SR_ID
AND C.T_STATU = 2
AND C.T_SRM <> 6
AND A.ISL_TAR >= '21/02/2011'
AND A.ISL_TAR <= '28/02/2011'
GROUP BY  B.HESAP_NO, A.TEKLIF_NO1 + '/' + A.TEKLIF_NO2,A.ISL_TAR,B.DOVIZ_KOD, B.HESAP_NO, B.MUS_K_ISIM, D.AVUKAT, C.ICRA_TAR, C.HACIZ_TAR, A.ODENEN_ANAPARA, A.FAIZ, A.BSMV, A.GECIKME_FAIZ, A.GECIKME_BSMV

但我得到了一个错误。

Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

我该如何解决这个问题?

最诚挚的问候,

Soner

2 个答案:

答案 0 :(得分:6)

这可能与你的dateformat设置有关。

这给我带来了同样的错误

set dateformat mdy
select 1
where GetDate() = '28/02/2011'

这不是

set dateformat dmy
select 1
where GetDate() = '28/02/2011'

您可以使用转换而不是设置dateformat

convert(datetime, '28/02/2011', 103) 

或者您可以使用始终有效的ISO格式

2011-02-28

答案 1 :(得分:1)

尝试始终使用ISO日期时间格式:“YYYYMMDD” 问题可能是SQL Server在字符串的第一部分中预期MONTH(MM / DD / YYYY是美国的日期方式) - 并且您使用“DD / MM / YYYY”=欧洲方式。