Coldfusion从第二个数据源获取数据

时间:2014-06-24 17:33:06

标签: sql sql-server coldfusion

我有一个从第二个数据源获取数据的查询。这很慢。有没有更有效的方法来做到这一点?

我认为缓慢的部分是ListQualify。它产生一个包含40,000个值的列表。但是我不确定另一种方法。

<cfif GetExtractionData.recordcount gt 0 >

            <cfquery name="queryVPOCar" datasource="Web_Applications">
                Select [strStockNumber] as "STOCK",
                        field1 as "field_1",
                        field2 as "field_2",
                        field3 as "field_3",
                        field4 as "field_4",
                        field5 as "field_5",
                        field6 as "field_6"
                From ExtractionAggregates
                WHERE [strStockNumber] IN (#ListQualify(StockList,"'",",","ALL")# )
            </cfquery>

        <!--- Select an empty Row --->
        <cfquery name="joinQuery" dbtype="query" >
            SELECT *
            FROM queryVPOCar
            WHERE queryVPOCar.STOCK = ''
        </cfquery>

        <!--- Add empty row to table, so we have column names  ---> 
        <cfset QueryAddRow(joinQuery) />

        <!--- if results exist, add them to the query --->
        <cfif queryVPOCar.recordcount gt 1 >
            <cfquery name="GetExtractionData" dbtype="query">

                SELECT * FROM 
                GetExtractionData, queryVPOCar
                WHERE GetExtractionData.STOCK = queryVPOCar.STOCK

                UNION 

                SELECT GetExtractionData.*, joinQuery.*
                FROM GetExtractionData, joinQuery
                WHERE GetExtractionData.STOCK  NOT IN (#ListQualify(ValueList(queryVPOCar.STOCK),"'",",","ALL")# ) 

                ORDER BY STOCK 
            </cfquery>
        </cfif>

    </cfif>

1 个答案:

答案 0 :(得分:13)

更好的方法是使用sql server进行尽可能多的数据库工作。第1步将在您的sql server上为您的oracle db安装linked server。第2步是编写一个存储过程:

  • 使用openquery从oracle获取数据并将该数据放入 你的SQL Server数据库的临时表。
  • 从连接到临时表的SQL Server数据库表中获取数据

步骤3是从ColdFusion调用存储过程并显示结果。