Solved Sql select statement and calculations

July 19, 2012 at 21:21:07
Specs: Windows 7, 2gb
I have a database with a table called employee with the following fields name.date of birth,sex,qualification,first appointment date,grade,date of licence,date of authority,date of appointment to current position. Am new to sql statement but can do basic select statements.

Now i need a statement that will show name,age(current year-date of birth),sex,qualification,years of service( current year - date of first appointment),years at current grade(current year - date of appointment to current position)

regards


See More: Sql select statement and calculations

Report •

✔ Best Answer
July 20, 2012 at 11:37:30
Untested:
SELECT name, 
       YEAR(GETDATE() - [date of birth]) AS age,
       sex, 
       qualification,
       YEAR(GETDATE() - [date of first appointment]) AS [years of service], 
       YEAR(GETDATE() - [date of appointment to current position]) AS [years at current grade]
FROM employee;

How To Ask Questions The Smart Way



#1
July 19, 2012 at 23:12:16
Have a look here: http://www.java2s.com/Code/SQL/Date... for some examples of computed fields using dates

Report •

#2
July 20, 2012 at 06:21:32
Someone should probably mention SQL syntax depends on the database in use.

How To Ask Questions The Smart Way


Report •

#3
July 20, 2012 at 10:20:20
its ms sql server 2008

Report •

Related Solutions

#4
July 20, 2012 at 11:37:30
✔ Best Answer
Untested:
SELECT name, 
       YEAR(GETDATE() - [date of birth]) AS age,
       sex, 
       qualification,
       YEAR(GETDATE() - [date of first appointment]) AS [years of service], 
       YEAR(GETDATE() - [date of appointment to current position]) AS [years at current grade]
FROM employee;

How To Ask Questions The Smart Way


Report •

Ask Question