存储过程中的逻辑
我需要存储过程中的一些逻辑。所有存储过程都会执行一些逻辑规则,然后根据结果返回 true 或 false。
伪 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 个字段 - 提供的字段(Date、Dis、Del 和 Sold)。
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.
The pseudo SQL code:
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
How do you do this sort of logic?
Notes about the code: The table #PV has 4 fields - those provided (Date, Dis, Del and Sold).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为什么每个人都创建临时表?变量表要好得多(性能更高): )
让我们看看...
祝你好运!
why is everyone creating a Temp Table? Variable tables are so much nicer (and more performant) :)
lets see...
Good luck!
标签是一件美丽的事情。 LABELS 允许您使用 GOTO,这使您可以在存储过程中编写简单易懂的逻辑。
LABELS are a beautiful things. LABELS allow you to use GOTO's and this lets you write simple to follow logic inside your stored procedures.
您需要声明一个变量并选择它
并使用 Dis 字段的正确类型进行声明。
编辑 - 更正返回值。
You need to declare a variable and select into it
Declare with the correct type of the Dis field.
Edit - corrected the return value.
// 使用SET或SELECT给@DisAvg赋值
RETURN
语句只能返回整数,可以使用SELECT
代替// use SET or SELECT to assign values to @DisAvg
Only integers can be returned from the
RETURN
statement, you can useSELECT
instead