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

來(lái)自局部變量的 MAXRECURSION 值

MAXRECURSION value from local variable(來(lái)自局部變量的 MAXRECURSION 值)
本文介紹了來(lái)自局部變量的 MAXRECURSION 值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在 SQL Server 2005 中編寫(xiě)一個(gè)存儲(chǔ)過(guò)程,它聲明了一個(gè)名為 foo 的 CTE(公用表表達(dá)式).

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

foo 遞歸調(diào)用自身,但當(dāng) SP 的參數(shù)之一 (@bar) 為空時(shí)無(wú)限循環(huán).

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

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

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

  • 當(dāng)@bar為空時(shí),設(shè)置MAXRECURSION為1;
  • 當(dāng) @bar 不為空時(shí),將 MAXRECURSION 設(shè)置為 0(無(wú)限制).
  • when @bar is null, set MAXRECURSION to 1;
  • when @bar is not null, set MAXRECURSION to 0 (no limit).

所以我聲明了一個(gè)局部變量 @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)

當(dāng)我解析代碼時(shí),出現(xiàn)以下錯(cuò)誤:'@maxrec' 附近的語(yǔ)法不正確.,指的是行 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).

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

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

推薦答案

一種選擇是構(gòu)建查詢,然后使用 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

附帶說(shuō)明,如果在語(yǔ)句完成之前達(dá)到 MAXRECURSION 值,查詢將不會(huì)正常結(jié)束,它將拋出異常.這可能就是您想要的,但請(qǐng)注意這一點(diǎn).

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.

這篇關(guān)于來(lái)自局部變量的 MAXRECURSION 值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開(kāi)發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱(chēng)轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 综合网在线 | 中文一区 | 亚洲国产中文字幕 | 国产精品欧美一区喷水 | 国产精品99久久久久久久久久久久 | 天天干天天爱天天操 | 国产精品av久久久久久久久久 | 欧美日韩成人在线观看 | 天天久 | 国产极品车模吞精高潮呻吟 | 日韩成人 | 美女视频h | 99久久精品视频免费 | 天堂中文在线观看 | 91精品国产综合久久福利软件 | 黄色播放 | 久久久91 | 国产成人一区二区 | 久久视频免费观看 | 免费观看成人鲁鲁鲁鲁鲁视频 | 看羞羞视频 | 成人性视频免费网站 | 国产亚洲一区二区三区在线观看 | 一级大黄色片 | 日日夜夜天天 | 日韩av成人| 成人国产精品久久 | 99国产精品99久久久久久 | 丝袜美腿一区二区三区动态图 | 国产成人啪免费观看软件 | 四虎影院在线观看免费视频 | 91成人精品视频 | www四虎影视 | 午夜天堂精品久久久久 | 精品久久久久久久久久久久久久 | 中文字幕国产视频 | 精品无码久久久久国产 | 欧美jizzhd精品欧美巨大免费 | 国产精品日韩在线观看一区二区 | 欧美日韩久久精品 | 亚洲一区二区网站 |