Abhilash J A

Abhilash J A

  • 533
  • 2.4k
  • 598k

More than one select query sql server 2008

Jan 25 2016 3:55 AM
Hi,

I have a sql server query:-

select distinct AL.Emp_id,ER.EmpName,ER.Address,AL.NumberOfDays as CasualLeave from AllowedLeaves AL inner join EmployeeRegistration ER on ER.Id = AL.Emp_id where LeaveType='CasualLeave' and Emp_id=20
select distinct AL.Emp_id,ER.EmpName,ER.Address,AL.NumberOfDays as SickLeave from AllowedLeaves AL inner join EmployeeRegistration ER on ER.Id = AL.Emp_id where LeaveType='SickLeave' and Emp_id=20
select distinct AL.Emp_id,ER.EmpName,ER.Address,AL.NumberOfDays as MyLeave from AllowedLeaves AL inner join EmployeeRegistration ER on ER.Id = AL.Emp_id where LeaveType='MyLeave' and Emp_id=20
select distinct AL.Emp_id,ER.EmpName,ER.Address,AL.NumberOfDays as Restricted_Holiday from AllowedLeaves AL inner join EmployeeRegistration ER on ER.Id = AL.Emp_id where LeaveType='Restricted Holiday' and Emp_id=20


The query result like this:-

Emp_id EmpName Address CasualLeave
20 Anita rgrfg 5.0

Emp_id EmpName Address SickLeave
20 Anita rgrfg 5.0

Emp_id EmpName Address MyLeave
20 Anita rgrfg 3.0

Emp_id EmpName Address Restricted_Holiday
20 Anita rgrfg 2.0


But I want result like this:-

Emp_id   EmpName   Address   CasualLeave  SickLeave   MyLeave  Restricted_Holiday

     20             Anita            rgrfg             5.0                5.0              3.0                 2.0



Answers (1)