ALTER PROCEDURE [dbo].[STL_ADDNEWROLE](@ROLENAME VARCHAR(100), @STATUS BIT)
AS
BEGIN
SET NOCOUNT ON;
IF(@ROLENAME IS NULL OR @STATUS IS NULL)
BEGIN
RETURN 0
END
ELSE
BEGIN
IF EXISTS (SELECT [RoleName], [Status] FROM ST_Roles
WHERE [RoleName] = @ROLENAME)
BEGIN
RETURN 0
END
ELSE IF(@ROLENAME IS NOT NULL)
BEGIN
INSERT INTO ST_Roles ([RoleName], [Status]) VALUES(@ROLENAME, @STATUS)
RETURN 1
END
END
END
以上是我的存储过程。当传递NULL值时,它应该返回0.即使传递了1个值而没有传递另一个值,它应该返回0而不是插入记录。
非常感谢任何帮助。
答案 0 :(得分:0)
在你描述你的问题之前,我只是猜测。我想问题是默认参数。也许你只是不传递参数或传递空字符串,所以试试这种方式
ALTER PROCEDURE [dbo].[STL_ADDNEWROLE](
@ROLENAME VARCHAR(100) = NULL,
@STATUS BIT = NULL)
AS
BEGIN
SET NOCOUNT ON;
IF(ISNULL(@ROLENAME, '') = '' OR @STATUS IS NULL)
BEGIN
RETURN 0
END
ELSE
BEGIN
IF EXISTS (SELECT [RoleName],[Status] from ST_Roles where [RoleName] = @ROLENAME)
BEGIN
RETURN 0
END
ELSE IF(@ROLENAME IS NOT NULL)
BEGIN
INSERT INTO ST_Roles ([RoleName],[Status]) VALUES(@ROLENAME,@STATUS)
RETURN 1
END
END
END