SQL Server interview questions: - Find the Age of an Employee whose Age is greater than 30 using SQL query.
- By Shiv Prasad Koirala in SQL
- Aug 19th, 2011
- 23798
- 0
SQL Server interview questions: - Find the Age of an Employee whose Age is greater than 30 using SQL query.
This is one of the most typical questions asked in most of the interviews and is the favorable question of interviewers to check your skill on SQL.
Many of the developer fail to query this question and because of that they also get rejected by the interviewers.
So, let's demonstrate a simple example to see how exactly we can achieve the above query in SQL.
Assume that we have the following table of Employee with their respective fields, data types and data.
Now assuming the above table, we have to display the employee names whose age is greater than 30.
In order to achieve the required result we have use SQL function called as "DATEDIFF".
DATEDIFF: - Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.
Syntax: -
DATEDIFF ( datepart , startdate , enddate )
Query: -
select Employees.EmployeeName, DATEDIFF(YEAR,EmployeeDOB,getdate())as Age from Employees where DATEDIFF(YEAR,EmployeeDOB,getdate())>= 30
The above SQL query set will give output like below diagram.
Hence you can see that Employee names have been displayed whose age is greater than 30.
An Informative video tutorial on how to improve SQL Server performance using profiler and tuning advisor.
Do not miss to view below SQL Server Interview Questions video with sample answers :-
Visit for more SQL Server interview questions | Author's blog for other SQL Server interview questions
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more