使用if条件时得不到任何结果,如果不使用if条件则得到结果 [英] Not getting any result while using if condition and getting the result if not using the if condition
本文介绍了使用if条件时得不到任何结果,如果不使用if条件则得到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
我是什么尝试过:
请帮助if块中的问题...感谢您的帮助
What I have tried:
Please help where is the issue in if block... Thanks for ur help
推荐答案
尝试 -
Try-
if((@FirstName is not null) or RTRIM(LTRIM(@FirstName)) != '')
希望,它有所帮助:)
Hope, it helps :)
这篇关于使用if条件时得不到任何结果,如果不使用if条件则得到结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文