| |

VerySource

 Forgot password?
 Register
Search
View: 854|Reply: 3

Help me see why this SQL stored procedure doesn't work

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-11 20:00:01
| Show all posts |Read mode
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
The goal is to run different branches with and without values ​​in @empState. The establishment of stored procedures is no problem. But when I run this stored procedure, I can't find the results. But there should be qualified results. Please take a look.
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 Unknown

Post time: 2020-1-16 11:18:02
| Show all posts
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
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-16 12:09:01
| Show all posts
Khan, cannot be judged by <> NULL, = NULL
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-19 00:30:01
| Show all posts
top
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list