久久久久久久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的网址 | 成人在线观看免费视频 | 亚洲天堂久久 | 成人性视频在线播放 | 亚洲一区二区精品视频 | 欧美久久久久久 | 午夜精品一区二区三区在线视 | 久久精品一区二区 | 成人免费在线视频 | 欧美日韩专区 | 日韩午夜网站 | 国产精品一区二区三区四区 | 成人免费视频网站在线看 | 国产欧美一区二区三区日本久久久 | 欧美视频一区二区三区 | 男人天堂色 | 日韩在线不卡视频 | 羞羞视频网站免费看 | 国产成人91视频 | 日韩在线观看中文字幕 | 成人欧美一区二区三区1314 | 北条麻妃一区二区三区在线观看 | 91精品国产91久久综合桃花 | 香蕉视频一区二区 | 国产精品一区免费 | av网站推荐| 国产精品视频二区三区 | 欧美成人一区二区三区片免费 | 亚洲 成人 在线 | 日韩成人av在线 | 精品二三区 | 国产高清精品在线 | 自拍偷拍中文字幕 | 国产精品一区二区福利视频 | 亚洲精品乱码久久久久久久久 |