database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
ㆍSybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Sybase Q&A 1925 게시물 읽기
No. 1925
뷰에 관한 질문...
작성자
경호선
작성일
2007-05-24 17:28
조회수
6,233

제가 아래와 같이 나이를 구하는 뷰를 만든 다음에요.

create view custom_age_view

as

select 'custom_cd'  = custom_cd,

       'age'  = datediff(yy, convert(datetime, birth_dt), getdate()),

       'birth_dt' = birth_dt

  from tbl 

 where isnull(birth_dt, '') != ''

   and datalength(birth_dt) = 8

   and substring(birth_dt, 1, 4) >= '1900'

   and substring(birth_dt, 5, 2) >= '01'

   and substring(birth_dt, 5, 2) <= '12' 



생성 한 뷰를


select * from custom_age_view where age between 0 and 99  이렇게 했는데


'Arithmetic overflow during explicit conversion of VARCHAR value '19408010' to a DATETIME field ' 

이런 에러가 나드라구요.


 birth_dt이 칼럼에 값이 틀리게 입력된게 있어서 걸를여구 뷰를 만든건데 에러가 나드라구요


해결할 수 있는 방법이 있을까요?



이 글에 대한 댓글이 총 2건 있습니다.

bitrh_dt 에 19408010 데이터가 들어가 있어서

convert(datetime, birth_dt) 문장에서 datetime으로 convert 못시켜서

발생하는 오류 입니다.


view 파싱시 age부터 만들고 where 조건을 체크하는 듯...(버그?)


case when 문장에 where조건을 복사하여 에러가 발생하면 99를

에러가 아닌경우는 나이를 구하도록 수정했습니다


create view custom_age_view

as

select 'custom_cd'  = custom_cd,

       'age'  = case when substring(birth_dt, 1, 4) >= '1900'   

                                   and substring(birth_dt, 5, 2) >= '01'       

                                   and substring(birth_dt, 5, 2) <= '12'  then

                                   datediff(yy, convert(datetime, birth_dt), getdate())

                           else 99 end,

       'birth_dt' = birth_dt

  from tbl

 where isnull(birth_dt, '') != ''

   and datalength(birth_dt) = 8

   and substring(birth_dt, 1, 4) >= '1900'

   and substring(birth_dt, 5, 2) >= '01'

   and substring(birth_dt, 5, 2) <= '12'

영빈~(backfish)님이 2007-05-25 09:57에 작성한 댓글입니다.

감사합니다..^^

경호선님이 2007-05-25 10:37에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1928alter database로 디바이스 추가시 [4]
궁금이
2007-05-25
5526
1927오라클의 external table과 같은 기능이 있나??? [2]
김종석
2007-05-25
5951
1926필드에 값이 있는지 체크하는 방법.. [4]
경아
2007-05-25
5242
1925뷰에 관한 질문... [2]
경호선
2007-05-24
6233
1924오라클의 greatest와 대응되는 함수나 SQL좀 [2]
초옵
2007-05-23
6082
1923[긴급] 커리좀 봐주세요... [3]
김철겸
2007-05-23
5654
1922select문에서 절사 [2]
꽃머슴
2007-05-23
7846
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다