排除storedprocedures中的字段 [英] exclude the fields in storedprocedures

查看:81
本文介绍了排除storedprocedures中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

我是asp.net和ms sql的新手。

所以,请帮助我。

我的问题是如何在存储过程中排除fileds。这意味着,例如我必须将5个字段传递给存储过程,但我想只传递3个字段,剩下的字段是离开。

如果像存储过程那样给出错误就像某些字段是期待一些价值。

请任何人都可以帮助我。



(继续在monsterindia搜索,我们可能只传递一些值。剩下字段留空,结果仍然没有错误.....所以,我想要这种类型的查询请帮帮我)

Hi..
I am new to asp.net and ms sql.
so, please help me.
My question is how to exclude fileds in stored procedures. it means, for example i have to pass 5 fields to stored procedure, but i want to pass only 3 fields, remaining fields are leave.
if do like the stored procedures give error "like some field is expected some value".
please any one can help me.

(resume searching in monsterindia, we may pass some values only. remaining fields are leave empty,still the result will come without errors..... so, i want like this type of query please help me)

推荐答案

使用默认值对于您希望在存储过程中作为可选项传递的参数



like



create proc [ SP_Name]

@ var1数据类型 - 必须传递

@ var2数据类型 - 必须传递

@ var3 = NULL或默认值你想要的 - 你传递它还是离开它

@ var4 = NULL或你想要的默认值 - 你传递它还是离开它

As

开始



- 根据参数值选择结果的逻辑

if(@ var3不为null和@ var4不是null)

开始

结束

否则if(@ var3为null且@ var4不为空)

开始

结束

否则if(@ var3为null且@ var4为null)

begin

结束





结束
Use default value for the parameter which you want to be passed as optional in stored procedure

like

create proc [SP_Name]
@var1 datatype -- must be passed
@var2 datatype -- must be passed
@var3 = NULL or Default value which you want -- either you pass it or leave it
@var4 = NULL or Default value which you want -- either you pass it or leave it
As
Begin

-- logic to select the result based on parameter values
if(@var3 is not null and @var4 is not null)
begin
end
else if(@var3 is null and @var4 is not null)
begin
end
else if(@var3 is null and @var4 is null)
begin
end


End


这篇关于排除storedprocedures中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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