如何从视图中使用动态SQL调用过程

发布于 2025-02-07 05:52:19 字数 524 浏览 4 评论 0原文

我正在尝试创建一个视图,该视图调用启动时的过程,以计算以下子句中使用的2个变量。查询运行,但不会作为视图保存,因为不允许出现过程调用。我研究了这一点,并发现了有关使用功能的一些建议,但是在尝试时,我会发现函数中不允许动态SQL的错误。 有没有办法做我正在尝试的事情?

代码段:

    CALL p_GetOutlierLimits('ROI_Imputed_Percent','DB1',@ClassicLowerROIPct, @ClassicUpperROIPct);
    CALL p_GetOutlierLimits('576_VMC_Sol_Savings_Pct','DB2',@vmctcoLower149Pct, @vmctcoUpper149Pct);
    
    USE Database;
    SELECT 
       {CODE}
    from TABLE
    WHERE ROI_Imputed_Percent BETWEEN @ClassicLowerROIPct AND @ClassicUpperROIPct;

I am trying to create a view that calls a procedure at initiation to compute 2 variables to be used in the WHERE clause. The query runs but will not save as a view as it appears procedure calls are not allowed. I researched this and found some suggestions about using a Function, but in trying that, I get errors that dynamic SQL is not allowed in a function.
Is there a way to do what I am attempting?

Code snippet:

    CALL p_GetOutlierLimits('ROI_Imputed_Percent','DB1',@ClassicLowerROIPct, @ClassicUpperROIPct);
    CALL p_GetOutlierLimits('576_VMC_Sol_Savings_Pct','DB2',@vmctcoLower149Pct, @vmctcoUpper149Pct);
    
    USE Database;
    SELECT 
       {CODE}
    from TABLE
    WHERE ROI_Imputed_Percent BETWEEN @ClassicLowerROIPct AND @ClassicUpperROIPct;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2025-02-14 05:52:19

我通过从视图中删除呼叫,并从访问视图的另一个过程中执行这些呼叫来找到另一种方法。

I found another way to do this by removing the calls from the view and just performing them from another procedure that accesses the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文