Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
interclubs
Yak Posting Veteran
63 Posts |
Posted - 2002-09-03 : 14:25:32
|
| I am trying to write a query to scan thru a table, and using a column called 'DOB' which is the user's Date of Birth, I need to figure out some demogrpahic information. Ideally it would provide somthing like this:10% 21yrs old16% 22yrs oldetc...But at this point I would take anything close. Anyone have any ideas or do they have some sample code? |
|
|
rharmon
Starting Member
41 Posts |
Posted - 2002-09-03 : 14:36:28
|
| Assuming you want a single row for each year of age, this may work. If not, you may have to join a table for the age grouping but the basics are still the same.declare @total_count floatselect @total_count = (select count(*) from contact)select datediff(yy,dob,getdate()), count(*)/@total_count from contactgroup by datediff(yy,dob,getdate())let me know what you think,Rob |
 |
|
|
|
|
|