ssis lookup with sum - can't map parameters
I have a sql query that looks like this:
SELECT SUM(A) AS expr1 FROM TREES WHERE (b = ?) AND (c = ?) and (d = ?)
Ho开发者_StackOverflow中文版w do I map the parameters? Since it's a sum, I can't select multiple rows.
A similar issue drove me up the wall today. Mapping the params is easy but then getting the summed value out may cause the real issues. So here are the settings I used in SSIS 2008. Key points I found:
- Your output columns are reliant upon the values you have in the Connection tab. So write your SELECT there but don't worry about the WHERE clause.
- Your input params are mapped on the Advanced tab
- The columns you have available for params on the Advanced tab must be used on the Columns tab but the actual mapping on the Columns tab will be ignored so just consider it a way of getting fields available for params on the Advanced tab.
This seems like a hack but I was able to use the same input column twice for the two conditions in my WHERE clause and get back a column based on SUM and a column based on COUNT.
General Tab: Cache mode: No cache (so I can used custom query on advanced tab) Connection type: OLE DB connection manager
Connection Tab: Use results of SQL query: checked Query: (has my sum functions for getting output but not my input params. The query will get overwritten on the Advanced Tab but I seemed to need to specify my outputs here in order to map my summed fields)
SELECT
MIN(Company) CompanyFromSecurityNumber
,COUNT(OLIFundId) FundCountForSecurityNumber
FROM [db].[dbo].[table]
Columns Tab: Map the columns you need to use as params from your input so they are available in your param list. Also check the summed values for Available Lookup Columns so you get the outputs. How you link doesn't matter though sinnce the Advanced tab will overwrite
Advanced Tab: Modify the SQL statement checked. (Had to have caching off on General Tab)
SELECT
MIN(Company) CompanyFromSecurityNumber
,COUNT(OLIFundId) FundCountForSecurityNumber
FROM
[db].[dbo].[table]
WHERE
CUSIP = ?
OR
ISIN = ?
Parameters button: Click and map params. The only ones available were those I used on the Columns Tab. Again, what I mapped to on the columns tab had nothing to do with their use as long as I used them properly here.
So that was it and I was able to use the params for input and get my summarized fields (MIN and COUNT) out in fields name "CompanyFromSecurityNumber" and "FundCountForSecurityNumber"
Although Hating Ohio answer is awesome and complete, for me it was way simpler to solve the problem. Just the first step, changing the source to SQL on the connection tab did the job.
Something like:
SELECT
[ID]
,[Date]
,SUM([CountStuff]) AS [CountStuff]
FROM [dbo].[Table]
GROUP BY [ID], [Date]
Then, match the columns and map the columns to the lookups and done.
精彩评论