How to find the employee having more than 5 years experience from table emp

Posted by Shreedar under ASP.NET on 8/25/2015 | Points: 10 | Views : 2265 | Status : [Member] | Replies : 1
I have a table with employee records like

id name salary date of join(doj) Bonus
--------------------------------------
101 sr 2000 10/01/1996
102 si 4000 12/12/2010
103 sd 5000 11/06/1994
104 sh 6000 09/02/1991
105 sa 2000 01/04/2015

I want to show all these in a gridview.

If an employee having more than 5 years experience then
that particular row should be highlighted and in bonus column
it should display "Yes".

Regards

Sridhar Thota.
www.dotnet-sridhar.blogspot.com



Responses

Posted by: Bandi on: 8/26/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
declare @tab table ( id int, name varchar(100), salary int,doj date, Bonus varchar(10))
insert into @tab
SELECT 101, 'sr', 2000, '10/01/1996', NULL union all
SELECT 102, 'si', 4000, '12/12/2010', NULL union all
SELECT 103, 'sd', 5000, '11/06/1994', NULL union all
SELECT 104, 'sh', 6000, '09/02/1991' , NULL union all
SELECT 105, 'sa', 2000, '01/04/2015', NULL
/*
If an employee having more than 5 years experience then
that particular row should be highlighted and in bonus column
it should display "Yes".
*/
SELECT *, Case when DATEDIFF(YY, doj, GETDATE()) >5 then 'Yes' ELSE 'No' END as Bonus
FROM @tab


Here @tab is table variable i used for the purpose of storing sample data...
You can replace @tab with your actual table name

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shreedar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response