gpt4 book ai didi

sql-server-2005 - 检查存储过程中的条件(sql server 2005)

转载 作者:行者123 更新时间:2023-12-03 01:23:47 25 4
gpt4 key购买 nike

我有一个 SP,我需要在其中检查 if 条件

ALTER   PROCEDURE [dbo].[spCheck]  
@strEmpname VARCHAR(50),
@intReturn INT OUTPUT,
@intWorkdID INT,
@intEmpID INT
AS

BEGIN
IF(@intWorkdID is not null and @intWorkdID != '')
BEGIN
IF EXISTS ( SELECT *
FROM Employee
WHERE [Empname] = @strEmpname
AND WorkID = @intWorkdID
)
SELECT @intReturn = '1'
END
ELSE
IF(@intEmpID is not null and @intEmpID != '')
BEGIN
IF EXISTS ( SELECT *
FROM Employee
WHERE [Empname] = @strEmpname
AND PeopleID = @intEmpID
)
SELECT @intReturn = '1'
END
ELSE IF(@intEmpID is not null and @intEmpID != '')
and(@intWorkdID is not null and @intWorkdID != '')
BEGIN
SELECT @intReturn = '0'
END

END

这里根据WorkID,EmpID
应执行 1 个条件和 2 个条件

如果两个条件都失败,我需要执行第三个条件

谁能告诉它的语法

谢谢

王子

最佳答案

最好的方法是你可以使用

尝试如下操作:

SELECT @intReturn = 
CASE
WHEN @intWorkdID IS NULL THEN 1
WHEN @intWorkdID<>'' THEN 1
WHEN @intEmpID IS NULL THEN 1
WHEN @intEmpID <>'' THEN 1
ELSE 0
END

Case... When

为此

关于sql-server-2005 - 检查存储过程中的条件(sql server 2005),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com