加入我有這樣一個查詢:重構與時態表
-- --JOIN one
LEFT MERGE JOIN
(SELECT TT.TAXAMOUNT,TT.TAXCODE,TT.TAXITEMGROUP,TT.VOUCHER,TT.TAXORIGIN, TTF.SOURCERECID
FROM TAXTRANS TT
INNER MERGE JOIN TAXTABLE TAX ON TAX.PAYMENTTAXCODE = TT.TAXCODE AND TAX.DATAAREAID = 'vb'
INNER MERGE JOIN TAXTRANS TTF ON TAX.TAXCODE = TTF.TAXCODE AND TTF.SOURCEDOCUMENTLINE = TT.SOURCEDOCUMENTLINE
WHERE TT.TRANSDATE between @FECHA_INI AND @FECHA
AND TT.TAXORIGIN = 11 AND ("[email protected]_IEPSCUOTAP_TT+")) TTIEPSCUOTA ON
C1.TT_VOUCHER = TTIEPSCUOTA.VOUCHER
AND C1.TT_TAXITEMGROUP = TTIEPSCUOTA.TAXITEMGROUP
AND PRO.TTF_SOURCERECID = TTIEPSCUOTA.SOURCERECID
--JOIN two
LEFT MERGE JOIN
(SELECT TT.TAXAMOUNT,TT.TAXCODE,TT.TAXITEMGROUP,TT.VOUCHER,TT.TAXORIGIN, TTF.SOURCERECID
FROM TAXTRANS TT
INNER MERGE JOIN TAXTABLE TAX ON TAX.PAYMENTTAXCODE = TT.TAXCODE AND TAX.DATAAREAID = 'vb'
INNER MERGE JOIN TAXTRANS TTF ON TAX.TAXCODE = TTF.TAXCODE AND TTF.SOURCEDOCUMENTLINE = TT.SOURCEDOCUMENTLINE
WHERE TT.TRANSDATE between @FECHA_INI AND @FECHA
AND TT.TAXORIGIN = 11 AND ("[email protected]_IEPS25P_TT+")) TTIEPS25 ON
C1.TT_VOUCHER = TTIEPS25.VOUCHER
AND C1.TT_TAXITEMGROUP = TTIEPS25.TAXITEMGROUP
AND PRO.TTF_SOURCERECID = TTIEPS25.SOURCERECID
正如你可以看到Join one
和Join two
是除了最後4行相同的連接,所以我決定創建一個臨時表來調用只選擇一次,如:
IF OBJECT_ID('tempdb..##TTC') IS NOT NULL DROP TABLE ##TTC
GO
SELECT * INTO ##TTC FROM (
SELECT
TT.TAXAMOUNT,
TT.TAXCODE,
TT.TAXITEMGROUP,
TT.VOUCHER,
TT.TAXORIGIN,
TT.SOURCERECID,
FROM TAXTRANS TT
INNER MERGE JOIN TAXTABLE TAX ON TAX.PAYMENTTAXCODE = TT.TAXCODE AND TAX.DATAAREAID = 'vb'
INNER MERGE JOIN TAXTRANS TTF ON TAX.TAXCODE = TTF.TAXCODE AND TTF.SOURCEDOCUMENTLINE = TT.SOURCEDOCUMENTLINE
WHERE TT.TRANSDATE between @FECHA_INI AND @FECHA
AND TT.TAXORIGIN = 11
GO
現在我都選擇了我的表,現在我想知道如何能實現與去年4行查詢我的態表,可有人幫忙嗎?問候
這是什麼數據庫服務器?你想要兩個聯盟的結果嗎?還是應該把這兩個聯繫作爲稅收交易的別名? –
sql server 2012,但我作爲OLEDB任務在SSIS項目上實現,我做臨時表是因爲這兩個使用相同的select,並且select有500多萬個寄存器,所以我只想調用一次保存到臨時表中,現在我想做的和我在原創一樣,但使用臨時表而不是選擇,因爲我的查詢的前六行是我的臨時表@ DanielGimenez – Benny
輸出怎麼樣,它只是兩個聯合或他們加入? –