开发者

SQL Error with Out-Of-Range

开发者 https://www.devze.com 2023-02-14 16:37 出处:网络
I have a SQL like this SELECTB.HESAP_NO, A.TEKLIF_NO1 + \'/\' + A.TEKLIF_NO2 AS \'TEKLIF\', B.MUS_K_ISIM, CONVERT(VARCHAR(10),A.ISL_TAR,103) AS \'TARIH\',

I have a SQL like this

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.BS开发者_JAVA技巧MV 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

But i getting an error this.

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.

How can i solve this problem?

Best Regards,

Soner


It has probably something to do with your dateformat setting.

This gives the same error for me

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

This does not

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

You can use convert instead of setting dateformat

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

Or you can use ISO format that will always work

2011-02-28


Try to allways use ISO datetime format: "YYYYMMDD" Problem is probably that SQL Server expects MONTH in first part of your string (MM/DD/YYYY is the american way of dates) - and you use "DD/MM/YYYY" = European way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号