How to Fetch matching Records following Query

Posted by Jayakumars under Sql Server on 7/20/2015 | Points: 10 | Views : 1364 | Status : [Member] [MVP] | Replies : 7
Create Table Emp1
(
EmpId int primary key identity(1,1),
EmpName varchar(40)
)


Create Table Emp2
(
Id int primary key identity(1,1),
EmpId int,
Concernname varchar(40),
JoinDt date,
Levg Date,
CurnWrkng varchar(40)
)


-- I need output Query those exployee which have to more then 2 years
-- How to write query following situation.

--for ex:
EmpID Empname Join Date LEaving Date TotalExp Concernname currentconcern
1 AA 20/07/2014 20/07/2015 1 ABC Tech YestTec
2 BB 20/07/2010 20/07/2015 5 Infosys Cad infos

etc...

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Sheonarayan on: 7/20/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Sorry, I misunderstood your question Jaya....

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Posted by: Jayakumars on: 7/20/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hello
sheo

What i m asking My output need pure sql server i have did not mention jquery i need pure sql server.

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

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

Posted by: Bandi on: 7/21/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SELECT e1.EmpName, e2.*, DATEDIFF(YY, e2.JoinDt, e2.Levg) TotalExp
FROM Emp1 e1
join Emp2 e2 on e1.EmpId = e2.EmpId
WHERE DATEDIFF(YY, e2.JoinDt, e2.Levg) >=2


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

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

Posted by: Jayakumars on: 7/21/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi
bandi

Thanks for your reply but i need also how to show some employee 2 month one conern
some employee 6 month some 1 or year so here how do show month and year

for ex:
Exp Month year
6 true false
1 false true
2 true false




Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

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

Posted by: Pankajchoudhary on: 8/21/2015 [Member] Starter | Points: 25

Up
0
Down
Hello Jayakumar you can use this query
SELECT e1.EmpName, e2.*, DATEDIFF(YY, e2.JoinDt, e2.Levg) TotalExp
FROM Emp1 e1
join Emp2 e2 on e1.EmpId = e2.EmpId
WHERE DATEDIFF(YY, e2.JoinDt, e2.Levg) >=2

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

Posted by: Pankajchoudhary on: 8/21/2015 [Member] Starter | Points: 25

Up
0
Down
Hello @Jayakumar you can use this query.
SELECT e1.EmpName, e2.*, DATEDIFF(YEAR, e2.JoinDt, e2.Levg) TotalExp
FROM Emp1 e1
join Emp2 e2 on e1.EmpId = e2.EmpId
WHERE DATEDIFF(YEAR, e2.JoinDt, e2.Levg) >2


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

Posted by: Pankajchoudhary on: 8/21/2015 [Member] Starter | Points: 25

Up
0
Down
Hello @Jayakumar can you elaborate your last query.......


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

Login to post response