带 sum 的 ssis 查找 - 无法映射参数

发布于 2024-12-05 16:39:27 字数 155 浏览 0 评论 0原文

我有一个如下所示的 sql 查询:

SELECT SUM(A) AS expr1 FROM TREES WHERE (b = ?) AND (c = ?) and (d = ?)

如何映射参数?由于它是总和,因此我无法选择多行。

I have a sql query that looks like this:

SELECT SUM(A) AS expr1 FROM TREES WHERE (b = ?) AND (c = ?) and (d = ?)

How do I map the parameters? Since it's a sum, I can't select multiple rows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-12-12 16:39:27

今天,类似的问题让我陷入了困境。映射参数很容易,但获取总和值可能会导致真正的问题。这是我在 SSIS 2008 中使用的设置。
我发现的要点:

  1. 您的输出列依赖于“连接”选项卡中的值。因此,将 SELECT 写在那里,但不用担心 WHERE 子句。
  2. 您的输入参数映射在“高级”选项卡上
  3. 您在“高级”选项卡上可用于参数的列必须在“列”选项卡上使用,但“列”选项卡上的实际映射将被忽略,因此只需将其视为获取可​​用于参数的字段的一种方法在“高级”选项卡上。

这看起来像是一个 hack,但我能够对 WHERE 子句中的两个条件使用相同的输入列两次,并返回基于 SUM 的列和基于 COUNT 的列。

常规选项卡:
缓存模式:无缓存(因此我可以在高级选项卡上使用自定义查询)
连接类型:OLE DB 连接管理器


连接选项卡:
SQL查询的使用结果:勾选
查询:(有我的求和函数用于获取输出,但没有我的输入参数。查询将在“高级”选项卡上被覆盖,但我似乎需要在此处指定我的输出以便映射我的求和字段)

SELECT 
    MIN(Company) CompanyFromSecurityNumber
   ,COUNT(OLIFundId) FundCountForSecurityNumber
FROM [db].[dbo].[table]

列选项卡:< /强>
映射您需要用作输入参数的列,以便它们在您的参数列表中可用。另请检查可用查找列的求和值,以便获得输出。您如何链接并不重要,因为“高级”选项卡将覆盖


高级选项卡:
修改检查的SQL语句。 (必须在“常规”选项卡上关闭缓存)

SELECT
   MIN(Company) CompanyFromSecurityNumber
   ,COUNT(OLIFundId) FundCountForSecurityNumber
FROM 
   [db].[dbo].[table]
WHERE
   CUSIP = ?
   OR
   ISIN = ?

“参数”按钮:单击并映射参数。唯一可用的是我在“列”选项卡上使用的那些。同样,我在列选项卡上映射到的内容与它们的使用无关,只要我在这里正确使用它们即可。


就是这样,我能够使用参数进行输入,并在字段名称“CompanyFromSecurityNumber”和“FundCountForSecurityNumber”中获取我的汇总字段(MIN 和 COUNT)

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:

  1. 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.
  2. Your input params are mapped on the Advanced tab
  3. 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"

甩你一脸翔 2024-12-12 16:39:27

尽管讨厌俄亥俄州的答案非常棒且完整,但对我来说,解决问题要简单得多。只需第一步,在连接选项卡上将源更改为 SQL 即可完成任务。

类似于:

SELECT 
[ID]
,[Date]
,SUM([CountStuff]) AS [CountStuff]
FROM [dbo].[Table]
GROUP BY [ID], [Date]

然后,匹配列并将列映射到查找并完成。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文