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

將 MS Sql 結果設置為變量并重用它

Set MS Sql result in variable and reuse it(將 MS Sql 結果設置為變量并重用它)
本文介紹了將 MS Sql 結果設置為變量并重用它的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

目前我的代碼是這樣的.

Currently my code is something like this.

select * 
from tblReq 
where ReqID in (select ReqID from tblLog where LogDate >= '2015/04/01' and LogDate < '2015/05/31')

只是想知道數據庫實際上是如何找到這個查詢的結果的?每次在子查詢中運行時都會重新運行嗎?是否有任何腳本可以將結果列表存儲在某個變量中并能夠重新使用它?(以下代碼)

Just wondering how actually the database find the result for this query? Is it re-run every time it ran in sub-query? And is there any script where I can store the list of result in some variable and able to use it back? (below code)

select @logs = tblLog.ReqID from tblLog where tblLog.LogDate >= '2015/04/01' and tblLog.LogDate < '2015/05/31'  
select * from tblReq where ReqID in (@logs)

推薦答案

是的,您可以將結果存儲在變量中并在以后多次重復使用.在您的情況下,它將是一個 table 變量,因為您可以有多個項目.然后,簡單的 join 到初始查詢:

Yes, you can store the result in a variable and reuse it several times later. In your case, it will be a table variable as you could have multiple items. Then, simple join it to the initial query:

DECLARE @Logs TABLE
(
    [LogID] INT
);

INSERT INTO @Logs ([LogID])
Select tblLog.ReqID 
from tblLog 
where tblLog.LogDate >= '2015/04/01' 
    and tblLog.LogDate < '2015/05/31'  

select * 
from tblReq A
INNER JOIN  @Logs L
    ON A.ReqID = L.LogID

此外,這可能會損害您的查詢性能,因為表變量不像查詢優化器的黑匣子.如果您要存儲大量行,請改用 temporary 表以使用并行執行計劃.

Also, this could harm your query performance, as table variables are not like black box for the query optimizer. If you are storing a large amount of rows, use temporary tables instead in order to use parallel execution plans.

這篇關于將 MS Sql 結果設置為變量并重用它的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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.com | 超碰在线人人 | 亚洲精品视频在线播放 | 国产精品区一区二区三区 | 国产美女一区 | 综合欧美亚洲 | 久久影音先锋 | 成人黄色av网址 | 呦呦在线视频 | 在线中文视频 | 免费看91| 亚洲国产免费 | 欧美精品乱码久久久久久按摩 | 国产探花在线观看视频 | 一级毛片观看 | 国产女人与拘做受视频 | 亚洲欧美国产视频 | 欧美伊人| 大吊一区二区 | 久久久久网站 | 伊人无码高清 | 最新国产视频 | 国产欧美一区二区精品忘忧草 | 美女亚洲一区 | www.操com| 国内自拍视频在线观看 | 国产婷婷色一区二区三区 | 欧美日韩中文字幕在线 | 99国产精品99久久久久久 | 婷婷福利 | 2020天天操|