即使空值保存数据后存储过程
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,而不是插入记录。
非常感谢任何帮助。
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
The above is my stored proc. When NULL values are passed it should return 0. Even when 1 value is passed and another value is not passed it should return 0 instead of inserting the record.
Any help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你描述你的问题之前,我先猜测一下。我认为问题出在默认参数上。也许您只是不传递参数或者传递空字符串,所以尝试这种方式
Before you describe your problem, I'll just guess. I suppose the problem is in default parameters. Maybe you just don't pass parameters or you pass empty string, so try this way