使用存储的数据进入查询SSIS

时间:2017-09-26 17:34:42

标签: sql ssis oledb dataflow

我有一个查询,我在那里获取数据,所以我将它存储到OLEDB Connection中,因为我想将这些数据多次用于另一个查询

查询

In [4001]: new_map
Out[4001]:
{'1': '3',
 '10': '12',
 '11': '12',
 '12': '12',
 '2': '3',
 '3': '3',
 '4': '6',
 '5': '6',
 '6': '6',
 '7': '9',
 '8': '9',
 '9': '9'}

In [4002]: period_dict
Out[4002]: {3: [1, 2, 3], 6: [4, 5, 6], 9: [7, 8, 9], 12: [10, 11, 12]}

In [4003]: df
Out[4003]:
  Period Ending
0        7/2017
1        4/2017
2        1/2017
3       10/2016
4        7/2016
5        4/2016

然后我创建了另一个OLEDB连接,其中我有另一个查询,其中我使用来自第一个查询的数据

第二次查询(仅限相关代码)

SELECT * FROM (
SELECT
TT.VOUCHER,
TT.TAXITEMGROUP,
TT.TAXCODE,
TT.SOURCEBASEAMOUNTCUR,
TT.SOURCETAXAMOUNTCUR,
TTGJAERIVA.TAXTRANSRELATIONSHIP,
TTGJAERIVA.GENERALJOURNALACCOUNTENTRY,
TTGJAERIVA.LEDGERDIMENSION,
GJAERIVA.TEXT,
GJAERIVA.LEDGERDIMENSION AS LEDGERDIMENSIONGAE,
GJAERIVA.POSTINGTYPE
FROM TAXTRANS TT 
INNER MERGE JOIN TAXTRANSGENERALJOURNALACCOUNTENTRY TTGJAERIVA ON TTGJAERIVA.TAXTRANS = TT.RECID
INNER MERGE JOIN GENERALJOURNALACCOUNTENTRY GJAERIVA ON TTGJAERIVA.GENERALJOURNALACCOUNTENTRY = GJAERIVA.RECID 
AND GJAERIVA.POSTINGTYPE IN( 14,236,71,41) 
AND TT.TRANSDATE <= '2015-04-30'
WHERE   
(TT.TAXORIGIN <> 11 AND TT.TRANSDATE BETWEEN  '2015-01-01' AND  '2015-04-30') OR (TT.TAXORIGIN = 11 AND TT.TRANSDATE BETWEEN '2015-01-01' AND  '2015-04-30' )) AS T

正如您所看到的,我在LEFT MERGE JOIN (SELECT TTRIVA.*,TTGJAERIVA.GENERALJOURNALACCOUNTENTRY FROM TAXTRANS TTRIVA INNER MERGE JOIN TAXTRANSGENERALJOURNALACCOUNTENTRY TTGJAERIVA ON TTGJAERIVA.TAXTRANS = TTRIVA.RECID INNER MERGE JOIN GENERALJOURNALACCOUNTENTRY GJAERIVA ON TTGJAERIVA.GENERALJOURNALACCOUNTENTRY = GJAERIVA.RECID AND GJAERIVA.POSTINGTYPE IN( 14,236,71) AND TTRIVA.TRANSDATE <=@FECHA) TTRIVA ON TT.VOUCHER = TTRIVA.VOUCHER AND TT.SOURCERECID = TTRIVA.SOURCERECID AND TT.TAXITEMGROUP = TTRIVA.TAXITEMGROUP AND (TTRIVA.TAXCODE LIKE 'RIVA%') AND TTRIVA.GENERALJOURNALACCOUNTENTRY = TTGJAE.GENERALJOURNALACCOUNTENTRY --JOIN PARA RETENCIONES DE ISR PAGADAS LEFT MERGE JOIN (SELECT TTRISR.*,TTGJAERIVA.GENERALJOURNALACCOUNTENTRY FROM TAXTRANS TTRISR INNER MERGE JOIN TAXTRANSGENERALJOURNALACCOUNTENTRY TTGJAERIVA ON TTGJAERIVA.TAXTRANS = TTRISR.RECID INNER MERGE JOIN GENERALJOURNALACCOUNTENTRY GJAERIVA ON TTGJAERIVA.GENERALJOURNALACCOUNTENTRY = GJAERIVA.RECID AND GJAERIVA.POSTINGTYPE IN( 14,236,71) AND TTRISR.TRANSDATE <=@FECHA) TTRISR ON TT.VOUCHER = TTRISR.VOUCHER AND TT.SOURCERECID = TTRISR.SOURCERECID AND TT.TAXITEMGROUP = TTRISR.TAXITEMGROUP AND (TTRISR.TAXCODE LIKE 'RISR%') AND TTRISR.GENERALJOURNALACCOUNTENTRY = TTGJAE.GENERALJOURNALACCOUNTENTRY --JOIN PARA IEPSCUOTA LEFT MERGE JOIN (SELECT TTIEPSCUOTA.*,TTGJAERIVA.GENERALJOURNALACCOUNTENTRY FROM TAXTRANS TTIEPSCUOTA INNER MERGE JOIN TAXTRANSGENERALJOURNALACCOUNTENTRY TTGJAERIVA ON TTGJAERIVA.TAXTRANS = TTIEPSCUOTA.RECID INNER MERGE JOIN GENERALJOURNALACCOUNTENTRY GJAERIVA ON TTGJAERIVA.GENERALJOURNALACCOUNTENTRY = GJAERIVA.RECID AND GJAERIVA.POSTINGTYPE IN( 14,236,71) AND TTIEPSCUOTA.TRANSDATE <=@FECHA) TTIEPSCUOTA ON TT.VOUCHER = TTIEPSCUOTA.VOUCHER AND TT.SOURCERECID = TTIEPSCUOTA.SOURCERECID AND TT.TAXITEMGROUP = TTIEPSCUOTA.TAXITEMGROUP AND (TTIEPSCUOTA.TAXCODE LIKE 'IEPSCUOTAP') AND TTIEPSCUOTA.GENERALJOURNALACCOUNTENTRY = TTGJAE.GENERALJOURNALACCOUNTENTRY 中使用了FROM TAXTRANS,但我在第一次查询中存储了LEFT JOIN。如何用第一个查询数据替换第二个查询?

数据流:

enter image description here

1 个答案:

答案 0 :(得分:0)

如果可以在单个集合中完成拆分查询并合并它,有什么需要?如果您仍然希望在单独的批处理基础上进行查询,我建议首先将要重用的查询插入到临时表(#表)中。使用该临时表左侧加入您的其他查询。将它全部封装在存储过程中然后获取数据。要进一步提高性能,请检查是否可以合并索引。

合并连接和排序是一种非常昂贵的转换,它会影响性能。此外,您正在寻求的是T-SQL改进,而SSIS转换不能替代