we have emp table like Ename,EDOJ,EDOB with Column
structure.but we want to know the employee Age.How? Any
Body Plz
Answers were Sorted based on User's Feedback
Answer / rajesh k. gupta
Hi,
In order to answer your question I would like to put all
three possible answers as follows:-
1.If You want to find out the age of employee as on the
date of Joining (Field name EDOJ) then Query will be
select *,datediff(year,EDOB,EDOJ) as Eage from emp
2. If you want to find out the age of employees as on
current date, query will be as follows:-
select *,datediff(year,EDOB,getdate()) from emp
3. If you want to find out age as on specific date stored
and taken from other variable then query will be :-
You need to declare a variable as datetime then need to
tore its value to it.
declare @dtb datetime
set @dtb='1990/01/10'
select *,datediff(year,EDOB,@dtb) from emp
---------------------------------------
For any clarification Please feel free to contact me.
Rajesh
9342284359
| Is This Answer Correct ? | 7 Yes | 1 No |
Answer / monal
FOR SQL 2005:
select datediff (day, birthdate, getdate())/365 from emp
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / santhi k
Answer i submitted is for Oracle not for SQL server.
Sorry!
Plz always mention the RDBMS which you are using ,in the
post.
Bcoz,This Oracle query may not work in other RDBMS.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / rajesh k. gupta
The answer submitted by Santhi K is wrong, Can shanti test
this query in sql server, because i ran it it does not
accept. there is no such months_between function
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / santhi k
select trunc(months_between(Sysdate,EDOB)/12)Age from emp;
| Is This Answer Correct ? | 0 Yes | 2 No |
How will you monitor replication activity and performance? What privilege do you need to use replication monitor? : sql server replication
what's the information that can be stored inside a bit column? : Sql server database administration
What is inner join? Explain with an example?
Define model database?
Difference between LEN() and DATALENGTH() in sql server ?
How to compare the top two records using sql?
what is Equity join?
What happens if null values are involved in bitwise operations?
How to Check if table exists in sql server?
How to enter comments in transact-sql statements?
What are the different types of cursor?
How to Display, Amount of Disk Activity Generated by Transact-SQL Statements?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)