2013-05-13 4 views
-2

유효하지 않은 datetime을 null로 바꾸려면 어떻게해야합니까?오버플로를 NULL로 대체하는 방법은 무엇입니까?

는 사실은 날짜 표현 인 INT 열 몇 가지 작업을하고있는 중이 야 : 날짜 있어야하는 정수 필드와

select 


DATEADD(DD, rbaging.billing_period_end - 693594, '1900-01-01'), 
DATEADD(DD, rbaging.billing_period_apply - 693594, '1900-01-01'), 

* 


from 

[kslap208].[c021]..RB_Resident_Aging rbaging 

join 
[kslap208].[c021]..PA_Profile_BASE_1119 pro 
on rbaging.bill_to_profile_id=pro.profile_id --4242 

join 
[kslap208].[c021]..PA_Admit_Det_BASE_10 unit 
on unit.profile_id=rbaging.bill_to_profile_id 

rbaging 테이블. 이 방법으로 지금까지 INT 변환

734562 
734776 
734837 

문서 상태를 : 여기에 샘플입니다

enter image description here 위 내 SQL 문을 실행, 난 점점 오전 :

Msg 517, Level 16, State 1, Line 1 
Adding a value to a 'datetime' column caused overflow. 

유효하지 않은 datetime을 null로 대체하는 방법은 무엇입니까?

+1

왜 0001 대신 1900에 요일을 추가하고 있습니까? 'SELECT DATEADD (DAY, 734562, CAST ('00010101'AS DATE))'괜찮아서'2012-03-01'을 반환합니다. –

+0

SQL Server 0001의 @MartinSmith가 유효하지 않습니다. –

+0

예 (최신 데이터 유형 포함). 이전 메모로 수정을 참조하십시오. –

답변

0
case when (rbaging.billing_period_end - 693594)>1 
then DATEADD(DD, rbaging.billing_period_end - 693594, '1900-01-01') 
else '' end, 

case when (rbaging.billing_period_apply - 693594)>1 
then DATEADD(DD, rbaging.billing_period_apply - 693594, '1900-01-01') 
else '' 
end 

은 매력처럼 작동합니다.

관련 문제