如何将空值传递给存储过程 [英] How to pass null value to Stored procedure

查看:180
本文介绍了如何将空值传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 null 值传递给我在控制器中调用的存储过程。我将其作为 null 传递,但没有获得正确的记录。该怎么办?



  //  我的代码 
// / span>
修改程序Proc
(@flag bit = Null)
As Begin

if @flag null
// 我的选择语句
结束

//

var data = _entites.GetData( null // 在控制器中调用SP





想要传递 null 某些条件

是不是很好?

解决方案

首先看 - sp中的if语句是不正确的。



看起来应该是这样的:



  DECLARE   @ flag   BIT  =  NULL  

IF @ flag IS NULL
PRINT ' 标记为空!'





如果在之后有超过1行,如果语句,你必须穿这在 BEGIN .. END 声明中。

  IF  @ flag   IS   NULL 
BEGIN
PRINT ' Flag null!'
PRINT '请停止传递 null 值!'
END





请参阅: IF ... ELSE(Transact-SQL) [ ^ ]



注意:请阅读< a href =http://www.codeproject.com/script/Membership/View.aspx?mid=11414469> F-ES Sitecore [ ^ ]对问题发表评论。


I want to pass null value to Stored procedure from where i am calling in controller. I am passing it as null but not getting correct records. how to do it?

// my code
//in stored procedure that parameter declred as null
Alter Procedure Proc
 (@flag bit= Null)
As Begin

if @flag is null
 //my select statement
end

//in controller
var data=_entites.GetData(null)//calling SP in controller 



want to pass null for some conditions
is it wirte?

解决方案

On the first look - if statement in sp is incorrect.

It should look like:

DECLARE @flag BIT = NULL

IF (@flag IS NULL)
    PRINT 'Flag is null!'



In case when there is more than 1 line after if statement, you have to "wear" this in BEGIN .. END statement.

IF (@flag IS NULL)
BEGIN
    PRINT &#39;Flag is null!&#39;
    PRINT &#39;Please stop passing null values!&#39;
END 



See: IF...ELSE (Transact-SQL)[^]

Note: please, read F-ES Sitecore[^] comment to the question.


这篇关于如何将空值传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆