如何进行以下查询工作?这是内部存储过程@GetClosedMeetings
bit
参数传递为true以获得已完成的会议,否则将获得计划和当前会议。 (状态:0 - 计划,1 - 当前,2 - 关闭)
SELECT
MeetingId, Status
FROM
dbo.Meeting
WHERE
Status IN (CASE
WHEN @GetClosedMeetings = 1 THEN 1
ELSE @OtherStatuses)
答案 0 :(得分:3)
如果我正确理解您的要求,如果@GetClosedMeetings
为TRUE
,您希望返回已完成的Meetings
,您的问题似乎有STATUS
2.另一方面,如果@GetClosedMeetings
是FALSE
,那么您希望获得计划和当前会议。以下是实现此目的的一种方法:
SELECT MeetingId, Status
FROM dbo.Meeting
WHERE
(@GetClosedMeetings = 1 AND Status = 2)
OR (@GetClosedMeetings = 0 AND Status IN(0, 1))
答案 1 :(得分:1)
使用它:
SELECT MeetingId, Status
FROM dbo.Meeting
WHERE (Status = 1 And @GetClosedMeetings = 1)
Or (Status <> 1 And @GetClosedMeetings <> 1 )
答案 2 :(得分:0)
你错过了案件
SELECT MeetingId, Status
FROM dbo.Meeting
WHERE Status IN
(CASE
WHEN @GetClosedMeetings = 1 THEN 1
ELSE @OtherStatuses end)