使用存储过程的输出作为条件 [英] Use output of Stored Procedure as where condition

查看:74
本文介绍了使用存储过程的输出作为条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程,它定义了基于条件的使用情况何时...我将此条件存储在存储过程的一个outpur变量中。



I我想现在在视图或查询中使用这个条件...


请指导如何做到这一点,还是有其他方法做同样的事情?

另请注意,我的情况是在定义整个条件时..它不仅给出了标准......比如=或>部分..


它是在...之后提供的...


任何人都可以指导我...

谢谢

I have one stored procedure, which defines where condition based useing Case when...I m storing this Condition in one outpur variable of Store procedure.


I would like to now use this condition in view or Query...

Pls guide how to do this or is there any other way of doing the same?

Also note that, my case when defines entire condition .. It is not only giving criteria... like = or > part..

It is giving everthing after where...

Can anyone guide me...

Thanks

推荐答案

请发布您正在处理的代码以供我们的专家参考。
kindly post the code that you are working on for reference of our experts.


请找到我的流程..


我有一个主表,其中我有客户ID和账单生成日期(称为BC)。另一张表是客户ID,付款金额和付款日期(字段名称Pdate)。


我的要求是找到客户明智的支付金额,但对于已关闭的BC。 BC在一个月后完全关闭。这也是,直到约会。我的意思是我的日期是从BC到今天,但那一天将在BC和它关闭之间落下......

这就是所谓的上个月相同日期。 (LMSD)。


为此,我要定义动态选择的条件。因为我写了以下过程。



创建proc lmsd

@bc smalldatetime,

@con varchar (500)输出

as


设置@con =大白天的情况(getdate() - 1)> day(@bc)然后

''天(pdate)天(b.bc)和day(getdate() - 1)''

else''天(天)(b.bc)和[dbo]。[ufn_GetDaysInMonth](b.bc)

或天(pdate)介于1和day之间(getdate() - 1)''end


现在我想在查询/查看的where子句中使用这个条件。


请帮助..它有点紧急。
Pls find my process..

I m having one master table where i m having Customer id and its bill generation date (called BC). Another table is having customer id, payment amount and payment date(field name Pdate).

My requirement is to find, payment amount customer wise, but for closed BC. BC Closed exactly after one month. And that too, till date. I mean my till date is from BC to the day of today but that day will fall between BC and its closure..
That is called Last Month Same Date. (LMSD).

To do so, i m defining where condition which will be opt dynamically. for that i have written following process.


Create proc lmsd
@bc smalldatetime,
@con varchar(500) output
as

set @con = case when day(getdate()-1) > day(@bc) then
''day(pdate) between day(b.bc) and day(getdate()-1)''
else ''day(pate) between day(b.bc) and [dbo].[ufn_GetDaysInMonth](b.bc)
or day(pdate) between 1 and day(getdate()-1)'' end


Now i want use this condition in where clause of my query / view.

Pls help.. Its bit URGENT.


将其转换为函数,以便将其嵌入查询中。


- CK
Convert it to function so that you can embed it on your query.

-- CK


这篇关于使用存储过程的输出作为条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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