select 회원ID, datediff(yy,convert(datetime, 주민번호컬럼,getdate())+1
from 회원테이블
이렇게 하시면 됩니다.
그럼 즐하세요.
-- 정윤호 님이 쓰신 글:
>> 안녕하세요??
>>
>> 나이구하는 쿼리문입니다..
>> 참고하세요.
>>
>> declare @age int, @year char(2)
>> declare @jumin1 char(6)
>>
>> set @jumin1 = '800101'
>>
>> set @year = substring(@jumin1,1,2)
>>
>> if convert(int,@year) > 50
>> set @age = convert(int,datepart(year,getdate())) - convert(int,'19'+@year)
>> else
>> set @age = convert(int,datepart(year,getdate())) - convert(int,'20'+@year)
>>
>> select @age
>>
>> -- 김제란 님이 쓰신 글:
>> >> 주민번호 컬럼이.. '800101' 이렇게 6자리 값으로 들어 있습니다..
>> >> 여기서.. 각 회원의 나이를 구해야되는데요..
>> >> 오라클처럼.. toChar 등의 함수를 사용할 수 없고..
>> >> SYSDATE 또한.. 지원하지 않는거 같아서..
>> >> 어떻게 해야할지 모르겠습니다...
>> >> 나이를 구할 수 있는 함수를 만들어 주세요..
|