Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SELECT membFNme, memberIdNum, MAX(DATEDIFF (YY,substring(memberIdNum, 1,6), GETDATE()))
FROM member
GROUP BY membFNme
HAVING  = MAX (DATEDIFF (YY,substring(memberIdNum, 1,6), GETDATE
I need to select the oldest member in the member table
Posted
Updated 19-Aug-10 7:50am
v2
Comments
shivaprasadk 19-Aug-10 8:22am    
Please mention clearly the requirement.
The DateDiff function gives difference between two date values. I don't think the MemberIdNum is the DateValue. Is it?
LittleYellowBird 19-Aug-10 8:25am    
Hi, there is no need to shout. I have removed the all capitals from your title as it appears to be shouting and is very rude. :)

Hi,

You have two options:

1. If the MemberIdNum column contains identity or continuous number, you can take first member as the Oldest member. B'coz, the first member will be the oldest member

2. If the MemberIdnum is containing the datevalue, then also the lowest MemberIDnum value is the oldest member

so, you can use:

select top 1 membFNme, MemberIdNum from member order by MemberIdNum
 
Share this answer
 
Comments
allaparaclatus 19-Aug-10 9:19am    
Thank you but i also need it to sho the age as well
shivaprasadk 19-Aug-10 12:09pm    
For getting the Age, you should have the member joining date (if age of work) or birth date (if age of employee)
Hi,

for getting the oldest member with Age, the query is:

select top 1 memnFNme, memberidNum, dateDiff(yy,membDOBirth,getdate()) as Age from Member
order by membDOBirth
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900