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
Does the order of columns in update statements matter?
What is log ldf?
How to list all stored procedures in the current database using ms sql server?
What is the importance of concurrency control?
Does index slows down insert statements?
What is store procedure? How do they work?
What is side by side migration in sql server?
What do you understand by user-defined function in the sql server?
What is the difference between createstatement and preparedstatement?
between cast and convert which function would you prefer and why?
How do you rename a table in sql server?
How to use transact-sql statements to access the database engine?
How to trouble shoot if unable to connect SQL Server
What is co-related sub query?
Is it important for a database administrator to understand the operating system and file access?