Thanks for your kind support. Now it is working very fine. I have created the procedure like below:
Create Procedure Pro_FDeptBind
As
Begin
Declare @Dept TABLE([auto] int IDENTITY(1,1) NOT NULL,
DeptId int,
DepartmentName varchar(100),
IsActive char(1) DEFAULT 0,
Flag char(1) DEFAULT 0,
CDate DateTime DEFAULT GETDATE()
)
insert into @Dept(DeptId,DepartmentName,IsActive,Flag,CDate)
select d.DeptId,d.DepartmentName,d.IsActive,d.Flag,d.CDate from DepartmentName d where d.DeptId=21
insert into @Dept(DeptId,DepartmentName,IsActive,Flag,CDate)
select d.DeptId,d.DepartmentName,d.IsActive,d.Flag,d.CDate from DepartmentName d where d.DeptId<>21 order by d.DepartmentName Asc
Select dn.DeptId,[auto],Case dn.DepartmentName when 'All' then
dn.DepartmentName + ' ('+ Convert(varchar(50),(Select Count(*) from Jobdetails where IsActive=0))+')'
else
dn.DepartmentName + ' ('+ Convert(varchar(50),Count(jd.DeptId))+')'
End as DepartmentName
from @Dept dn LEFT OUTER JOIN jobdetails jd
on dn.DeptId=jd.DeptId where dn.IsActive=0
and flag=0 and dn.DepartmentName is not null GROUP by dn.DeptId,dn.DepartmentName ,[auto]
order by [auto]
End