Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
alter procedure ListEmployeedtls_Paging
@FirstName varchar(200)

as
begin
Declare @result nvarchar(4000);
Declare @orderby nvarchar(700);
Declare @PageSize nvarchar(200);
Declare @PageNum nvarchar(200);
Declare @Offset nvarchar(200);




set @orderby=' order by e.EmpId desc';

set @PageSize=10
set @PageNum=1
set @Offset=@PageSize*(@PageNum-1)



set @Result='select Top '+@PageSize+' e.EmpId
,(e.FirstName+'' ''+e.LastName) as EmpName
,e.EmpMobile
,e.EmpGender
,e.EmpAddress
,e.IsActive
,e.EmpEmail
,e.EmpSalary
,d.DeptName

,convert(varchar(10),e.JoiningDate,103) as JoiningDate
, convert(varchar(10),e.EmpDateOfBirth,103) as EmpDateOfBirth

,e.SupervisorId
,(s.FirstName+'+' '+'+s.LastName) as SupervisorName
,g.GradeName
,r.Rolename 
,e.Password


from Employeedtls e left outer join Department d on d.DeptId=e.DepartmentId
left outer join Grade g on g.GradeId=e.GradeId 
left outer join User_Role r on r.RoleId=e.RoleId
left outer  join Employeedtls s on e.SupervisorId=s.EmpId 
where 1=1  
and e.EmpId not in

 (select  top '+@Offset+' e1.EmpId
from Employeedtls e1 
left outer join Department d1 on d1.DeptId=e1.DepartmentId
left outer  join Employeedtls s1 on e1.SupervisorId=s1.EmpId
left outer join Grade g1 on g1.GradeId=e1.GradeId 
left outer join User_Role r1 on r1.RoleId = e1.RoleId where 1=1) '


if((@FirstName is not null) or @FirstName!='''')
begin
set @Result=@Result+' and  e.FirstName like ''% @FirstName %'''
end

	

print @Result



	
	
print @Result+ @orderby

exec (@Result + @orderby)
end


What I have tried:

Please help where is the issue in if block... Thanks for ur help
Posted
Updated 29-May-17 21:40pm
v2

1 solution

Try-
SQL
if((@FirstName is not null) or RTRIM(LTRIM(@FirstName)) != '')

Hope, it helps :)
 
Share this answer
 
Comments
Member 10013883 30-May-17 5:11am    
still it is not working...Thank u for your responce

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900