Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



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

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

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

Answer / reddy

Thanks Rajesh K. Gupta.

Is This Answer Correct ?    4 Yes 0 No

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

Answer / monal

FOR SQL 2005:

select datediff (day, birthdate, getdate())/365 from emp

Is This Answer Correct ?    2 Yes 1 No

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

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

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

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

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

Answer / santhi k

select trunc(months_between(Sysdate,EDOB)/12)Age from emp;

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More SQL Server Interview Questions

Explain datetime2 data type in sal server 2008?

0 Answers  


How to connect of datebase with sql express.?

0 Answers   MCN Solutions,


What are extended events in sql server?

0 Answers  


What is the difference between for trigger and after trigger?

0 Answers  


What are the steps you will take, if you are tasked with securing an SQL Server?

1 Answers   HCL,


CREATE TABLE [dbo].[HPMS_CompetencyTypes](CompetencyType varchar(50) ) go create trigger hpms_create_Insert on HPMS_CompetencyTypes for insert as if Exists ( select * from [HPMS_CompetencyTypes] where CompetencyType=(select * from [HPMS_CompetencyTypes])) begin Rollback tran Raiserror ('duplicate value',12,6) go insert HPMS_CompetencyTypes (CompetencyType) values ('new') I'm new to trigger can any one tell me where is the issue. Please.

2 Answers  


How to create a login account in ms sql server to access the database engine using "create login" statements?

0 Answers  


How you can find out if an index is useful to the optimizer?

0 Answers  


Other than truncate statement, which other command can by-pass the trigger on the tables?

0 Answers  


What are the different types of lock modes in sql server 2000?

0 Answers  


syntax for deleting the database in T SQL

5 Answers  


What are the different ways of moving data/databases between servers and databases in SQL Server?

3 Answers   HCL,


Categories