久久久久久久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 的參數之一 (@bar) 為空時無限循環.

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

為了停止這個無限循環,我一直在嘗試使用選項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,它根據 @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)

當我解析代碼時,出現以下錯誤:'@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模板網!

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

相關文檔推薦

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?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日韩高清中文字幕 | 国产日韩欧美一区 | 狠狠干av | 99免费在线观看 | 色吧综合网 | 91在线影院 | 日本成人在线免费视频 | 无码一区二区三区视频 | 日日摸夜夜爽人人添av | 天堂一区二区三区 | 精品九九九 | 欧美日韩不卡合集视频 | 久久一级大片 | 日韩一区中文字幕 | 亚洲精品一区二区三区在线 | 欧美久久一区二区三区 | 精品视频在线播放 | 亚洲h色 | 精品国产一区二区三区久久 | 91亚洲一区 | 欧美二级 | 亚洲av毛片 | 久久久www | 欧美一级久久久猛烈a大片 日韩av免费在线观看 | 久久躁日日躁aaaaxxxx | 国产99热 | 懂色中文一区二区在线播放 | 欧美福利视频 | 国产精品久久久久久久岛一牛影视 | 欧美一级大片免费观看 | 亚洲一区二区免费 | 亚洲综合第一页 | 久久久国产一区二区三区 | 欧洲在线视频 | 成年人在线电影 | 亚洲h在线观看 | 日本一二区视频 | 国产精品视频观看 | 91夜色在线观看 | 欧美激情综合 | 日本精品视频在线 |