存储过程中的逻辑 [英] Logic in stored procedure
本文介绍了存储过程中的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要存储过程中的一些逻辑.所有存储过程都会执行一些逻辑规则,然后根据结果返回真或假.
I have need of some logic in a stored procedure. All the stored procedure does it perform a couple of logic rules and then returns a true or false depending on the result.
伪SQL代码:
CREATE TABLE #PV ([Date] DATETIME, Dis FLOAT, Del Float, Sold Float)
INSERT #PV exec GetPVSummaryReport @ID, @PID, @From, @To
SELECT AVG(Dis) / 8 AS DisAvg, AVG(Del) AS DelAvg FROM #PV
IF DisAvg > 20 -- this is the bit I am having problems grokking
RETURN TRUE
ELSE
-- do longer calculation
你是怎么做这种逻辑的?
代码说明:#PV 表有 4 个字段 - 提供的字段(日期、Dis、Del 和 Sold).
Notes about the code: The table #PV has 4 fields - those provided (Date, Dis, Del and Sold).
推荐答案
declare @DisAvg float
declare @DelAvg float
-- Instantiate #PV etc
select
@DisAvg = avg(Dis) / 8,
@DelAvg = avg(Del)
from
#PV
if @DisAvg > 20
return
else
-- Do something else
这篇关于存储过程中的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文