we have emp table like Ename,EDOJ,EDOB with Column
structure.but we want to know the employee Age.How? Any
Body Plz

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the types of indexes.

834


How can we check the sql server version?

737


Can you type more than one query in the query editor screen at the same time?

770


What is the usage of sign function?

774


How to loop through result set objects using odbc_fetch_row()?

645






How to create a view on an existing table in ms sql server?

793


If you're given a raw data table, how would perform etl (extract, transform, load) with sql to obtain the data in a desired format?

719


Can you pass expressions to stored procedure parameters?

702


Do you know what are different types of replication in sql server?

734


What is purpose of normalization?

700


Explain what are commit and rollback in sql?

674


What is the significance of master, tempdb and model databases?

706


Explain what are magic tables in sql server?

697


What are data regions?

107


What is a print index?

661