帮我看看这个SQL的存储过程为什么运行不了
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER procedure CombinedSearch
@StartTime smalldatetime,
@EndTime smalldatetime,
@empState varchar(100)= null
as
if @empState <> null
select * from jobseeker
where (@StartTime <=InterviewTime and @EndTime> =InterviewTime) and empState=@empState
else if @empState=null
select * from jobseeker
where (@StartTime <=InterviewTime and @EndTime> =InterviewTime)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
目的是在@empState有值是和没有值是分别运行不同的分支。存储过程的建立没有问题的。但是我运行这个存储过程时去搜索不到结果。但是应有符合条件的结果的。请各位看看。
------解决方案--------------------SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER procedure CombinedSearch
@StartTime smalldatetime,
@EndTime smalldatetime,
@empState varchar(100)= null
as
if @empState is not null
select * from jobseeker
where (@StartTime <=InterviewTime and @EndTime> =InterviewTime) and empState=@empState
else if @empState is null
select * from jobseeker
where (@StartTime <=InterviewTime and @EndTime> =InterviewTime)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
------解决方案--------------------汗, 不能用 <> NULL, =NULL 來判斷的