Home SQLSQL Server interview questions: - Find the Age of an Employee whose Age is greater than 30 using SQL query.
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 Agefrom 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.
View the following video on how to improve SQL Server performance using profiler and tuning advisor
Visit for more SQL Server interview questions
Regards,
Also author’s blog for otherSQL Server interview questions




Write a Comment
All fields marked with * are mandatory
ASP.NET interview questions: - Can you explain Method of Sorting GridViewcontrol in ASP.NET?
Sorting allow you to sort the GridViewcontrol data in Ascending or Descending order.... Read More
By : Shiv Prasad Koirala | Aug 4th, 2011 | ASP.NET
WCF Interview questions:- Which binding do we need to use for WCF REST?
In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More
By : Shiv Prasad Koirala | Nov 16th, 2011 | WCF
.NET interview questions: - Can you elaborate project life cycle?
In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More
By : Shiv Prasad Koirala | Jan 17th, 2012 | .Net
.NET interview questions: - How will you distinguish between ForeGround and BackGround Threading?
threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time.... Read More
By : Shiv Prasad Koirala | Sep 27th, 2011 | ASP.NET
C# interview questions: - Explain anonymous methods in .NET?
n simple words Anonymous Methods means method which are coded inline or methods without method name.... Read More
By : Shiv Prasad Koirala | Aug 5th, 2011 | C#
ASP.NET interview questions: - Can you explain Method of Sorting GridViewcontrol in ASP.NET?
Sorting allow you to sort the GridViewcontrol data in Ascending or Descending order.... Read More
By : Shiv Prasad Koirala | Aug 4th, 2011 | ASP.NET
WCF Interview questions:- Which binding do we need to use for WCF REST?
In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More
By : Shiv Prasad Koirala | Nov 16th, 2011 | WCF
.NET interview questions: - Can you elaborate project life cycle?
In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More
By : Shiv Prasad Koirala | Jan 17th, 2012 | .Net
.NET interview questions: - How will you distinguish between ForeGround and BackGround Threading?
threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time.... Read More
By : Shiv Prasad Koirala | Sep 27th, 2011 | ASP.NET
C# interview questions: - Explain anonymous methods in .NET?
n simple words Anonymous Methods means method which are coded inline or methods without method name.... Read More
By : Shiv Prasad Koirala | Aug 5th, 2011 | C#
Article Categories
YouTube Videos