久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

來自局部變量的 MAXRECURSION 值

MAXRECURSION value from local variable(來自局部變量的 MAXRECURSION 值)
本文介紹了來自局部變量的 MAXRECURSION 值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在 SQL Server 2005 中編寫一個存儲過程,它聲明了一個名為 foo 的 CTE(公用表表達式).

I'm writing a Stored Procedure in SQL Server 2005 that declares a CTE (Common Table Expression) called foo.

foo 遞歸調用自身,但當 SP 的參數(shù)之一 (@bar) 為空時無限循環(huán).

foo calls itself recursively, but loops infinitely when one of the SP's parameters (@bar) is null.

為了停止這個無限循環(huán),我一直在嘗試使用選項MAXRECURSION:

To stop this infinite loop, I've been trying to use the option MAXRECURSION:

  • @bar為空時,設置MAXRECURSION為1;
  • @bar 不為空時,將 MAXRECURSION 設置為 0(無限制).
  • when @bar is null, set MAXRECURSION to 1;
  • when @bar is not null, set MAXRECURSION to 0 (no limit).

所以我聲明了一個局部變量 @maxrec,它根據(jù) @bar 是否為空取 1 或 0.

So I've declared a local variable @maxrec that takes 1 or 0 depending on whether @bar is null or not.

DECLARE @maxrec INT;
SET @maxrec = 0;
if (@dim_course_categories is null)
begin
    SET @maxrec = 1;
end

;WITH foo AS (
    ...
)

SELECT * FROM foo
OPTION (MAXRECURSION @maxrec)

當我解析代碼時,出現(xiàn)以下錯誤:'@maxrec' 附近的語法不正確.,指的是行 OPTION (MAXRECURSION @localvar).

When I parse the code, I get the following error: Incorrect syntax near '@maxrec'., which refers to the line OPTION (MAXRECURSION @localvar).

那我做錯了什么?是否禁止在 OPTION 子句中使用局部變量?

So what am I doing wrong? Is it forbidden to use a local variable within an OPTION clause?

推薦答案

一種選擇是構建查詢,然后使用 EXEC sp_executesql

One option would be to build the query and then execute it with EXEC sp_executesql

DECLARE @Query NVARCHAR(MAX)

SET @Query = N'
    ;WITH foo AS (
        ...
    )

    SELECT * FROM foo
    OPTION (MAXRECURSION ' + CAST(@maxrec AS NVARCHAR) + ');'

EXEC sp_executesql @Query

附帶說明,如果在語句完成之前達到 MAXRECURSION 值,查詢將不會正常結束,它將拋出異常.這可能就是您想要的,但請注意這一點.

On a side note, if the MAXRECURSION value is reached before the statement completes, the query will not end gracefully, it will throw an exception. That may be what you want, but just be aware of it.

這篇關于來自局部變量的 MAXRECURSION 值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內的計算值創(chuàng)建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 看毛片网站 | 久久久久久成人 | 欧美精品在线视频 | 日韩在线精品强乱中文字幕 | 美国av毛片 | 国产三级日本三级 | 天天想天天干 | 国产欧美日韩综合精品一 | 久久在看 | 久久精品国产免费看久久精品 | www网站在线观看 | 国产亚洲精品美女久久久久久久久久 | 一区二区三区四区在线免费观看 | 精品国产乱码久久久久久蜜柚 | 国产成人精品免费 | 中文字幕一区二区三区在线观看 | 欧美一区二区三区 | 真人毛片| 欧美最猛黑人xxxⅹ 粉嫩一区二区三区四区公司1 | 欧美视频在线看 | 97久久久久久久久 | 午夜影院在线播放 | 精品日韩在线 | 91在线看| 老司机成人在线 | 龙珠z在线观看 | avhd101在线成人播放 | 狠狠婷婷综合久久久久久妖精 | www.蜜桃av.com| 日韩中文字幕在线视频 | 在线视频中文字幕 | 亚洲天堂av一区 | 在线国产一区二区三区 | 99久热| 国产精品一区一区 | 亚洲九九 | 国产精品一区久久久 | 亚洲一区二区三区在线视频 | 日韩一二三区视频 | 91av在线免费 | 国产亚洲一区二区在线观看 |