【问题标题】:Viewing a programs database query and duplicating查看程序数据库查询和复制
【发布时间】:2018-03-29 06:26:02
【问题描述】:

我们有一个服务器,其中包含一个完整的财务记录数据库,其中信息是通过一个名为 MDA 的财产管理程序获取的。 MDA 具有报告功能。

是否可以查看程序正在查询数据库的具体内容,以便我可以在 Excel 等中复制该特定报告表。

MDA 帮助页面确实提供了一些报告的 sql 代码,但不是全部,并且提供的一些代码没有提供相同的信息。那么是否有可能从服务器端确切地看到正在做什么?

编辑:

以下是捕获的查询:

Update tmp  Set 
tmp.TenantReceipts                  = a.TenantReceipts, 
tmp.OtherReceipts                   = a.OtherReceipts,      
tmp.Disbursments                    = a.Disbursments, 
tmp.AgentFeesCollectionCommission   = a.AgentFeesCollectionCommission, 
tmp.AgentFeesManagementFee          = a.AgentFeesManagementFee, 
tmp.AgentFeesBankCharges            = a.AgentFeesBankCharges,   
tmp.AgentOnlyCashMovements          = a.AgentOnlyCashMovements,  
tmp.PaidToOwners                    = a.PaidToOwners 

From #tmpResultSet tmp
Inner Join 
(Select PropertyID, IsNull(CashBookID, 0) as CashBookID,    

--Tenant Receipts   Sum of tenant receipts (type = 2) and tenant payments (type = 3), excluding agent only transactions, for either financial or owner statement period. 
Sum (Case When TransactionTypeID in (2,3) and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end)   as TenantReceipts, 

--Other Receipts    Sum of suppier receipts (type = 12 not used) and property receipts (type = 22), excluding agent only transactions, for either financial or owner statement period.
Sum (Case When TransactionTypeID in (12,22) and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end)   as OtherReceipts,    

--Disbursements Sum of suppier payments (type = 13) and property payments (type = 23), excluding agent only transactions, for either financial or owner statement period.
--Excludes transactions designated as Agent Fees in Global Options i.e Collection Commission, Management Fee, Bank Charge son Cash, Bank Charges on Cheques (includes all payments)  and Bank Charges on Cash, as well as amounts Paid to Owners. 
Sum (Case When TransactionTypeID in (13,23) 
                --and IsNull(afgo.TransactionCodeID, 0 ) = 0 
                and tx.TransactionCodeID not in (@CollectionCommissionID)
                and tx.TransactionCodeID not in (@ManagementFeeID) 
                and tx.TransactionCodeID not in (@BankChargesOnCashID)
                and tx.TransactionCodeID not in (@BankChargesOnChequesID)
                and tx.TransactionCodeID not in (@OwnerPaymentsID)  
                and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end)   as Disbursments, 

--Agent Fees    For Amounts Paid:
--If any of the Agent Fee components are unchecked on the parameter screen, they will be excluded from the calculation.
--Sum of supplier payments (type = 13) and property payments (type =23), excluding agent only transactions, for either financial or owner statement period. 
--Further restricted to transactions designated in Global Options as Collection Commission, Management Fee and Bank Charges, and if ticked on the parameter form.

--Agent Fees    Collection Commission
Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowCollectionCommission = 1
                and tx.TransactionCodeID in (@CollectionCommissionID) then InclusiveAmount else 0 end)   as AgentFeesCollectionCommission,  

--Agent Fees    Management Fee  
Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowManagementFee = 1
                and tx.TransactionCodeID in (@ManagementFeeID) then InclusiveAmount else 0 end)   as AgentFeesManagementFee,    

--Agent Fees    Bank Charges    
Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowBankCharges = 1
                and (tx.TransactionCodeID in (@BankChargesOnCashID) or tx.TransactionCodeID in (@BankChargesOnChequesID)) 
                then InclusiveAmount else 0 end)   as AgentFeesBankCharges, 

--Agent Only (Cash) Movements   Sum of cash transactions (types = 2, 3, 12, 13, 22 and 23) and where such transactions are designated as ‘agent only, for either financial or owner statement period.
Sum (Case When TransactionTypeID in (2, 3, 12, 13, 22, 23) and ExcludeFromOwnerReports = 1 then InclusiveAmount else 0 end)   as AgentOnlyCashMovements,    

--Paid to Owners    Sum of property payments (type = 23) allocated to the Owner Payment transaction code in Global Options, excluding agent only transactions, for either financial or owner statement period.
Sum (Case When TransactionTypeID in (13, 23)    --RB 05/08/2009 Added Transaction Type 13 where expense accruals are paid to owner payment codes
    and ExcludeFromOwnerReports = 0
    and tx.TransactionCodeID = @OwnerPaymentsID
    then InclusiveAmount else 0 end)  as PaidToOwners   

From Transactions tx  (NoLock)  
Where ( (@UseFinPeriod = 1 and tx.Period =  @Period)     or (@UseFinPeriod = 0 and tx.OwnerStatPeriod = @Period) )
  and ((@IncludeRegularTransactions = 1 and @IncludeAgentOnlyTransactions = 1) 
          or (tx.ExcludeFromOwnerReports = 0 and @IncludeRegularTransactions = 1)
          or (tx.ExcludeFromOwnerReports = 1 and @IncludeAgentOnlyTransactions = 1)
          )
  and (@GenerateOwnerPayments = 0 or @PropertyDefaultCashBookID = tx.CashBookID)
  and tx.PropertyID in (Select PropertyID from #tmpProperties)

Group By tx.PropertyID, tx.CashBookID
--Order by tx.PropertyID
) a     on a.PropertyID = tmp.PropertyID and a.CashBookID = tmp.CashBookID

如何通过 Powerbi 或 PowerQuery 使用上述查询?因为它不能只是添加,因为我假设上面的“tmp”添加了临时表,并且从查询端无法修改数据库。并且所有的@都必须被赋予值?

【问题讨论】:

    标签: sql powerbi powerquery


    【解决方案1】:

    我假设底层数据引擎是 SQL Server。 在这种情况下考虑使用 SQL Profiler,因为它可以捕获所有传入的查询并提供执行统计信息,例如持续时间、IO 和 CPU 成本等。Example


    更新:

    您提供的查询包含临时表和变量。 因此,该临时表的创建也必须通过探查器进行跟踪。 当涉及到变量值时,可以通过跟踪事件"Showplan XML Statistics Profile"找到它们

    例子:

    <ParameterList>
      <ColumnReference Column="@P3" ParameterCompiledValue="'2012-03-04 05:06:07.080'" ParameterRuntimeValue="'2012-03-04 05:06:07.080'" />
      <ColumnReference Column="@P2" ParameterCompiledValue="N'StrVal1'" ParameterRuntimeValue="N'StrVal1'" />
      <ColumnReference Column="@P1" ParameterCompiledValue="(17)" ParameterRuntimeValue="(17)" />
    </ParameterList>
    

    除此之外,如果您的数据来自本地数据网关,请考虑以下几点:

    问题:如何查看正在发送到本地的查询 数据来源?

    回答:您可以启用查询跟踪。这将包括 正在发送的查询。记得改回原来的 完成故障排除时的价值。启用查询跟踪将 导致日志更大。

    Reference

    【讨论】:

    • 所以如果我想在 PowerQuery 中复制上述查询,我​​可以输入变量值吗?对于最终表,我应该首先跟踪临时表,复制这些临时表,然后调整上面提供的查询以运行这些临时表?
    • 没错,序列的所有部分都必须被跟踪,包括临时表的创建。此外,变量要替换为实际值。
    • 能否请您澄清一下如何从“Showplan XML Statistics Profile”中获取参数列表,如您的示例中所示。我已经添加了它,但它只提供执行映射,而不是您的示例中的信息。之前运行的参数代码是 'exec [MDAmanager]..sp_procedure_params_rowset N'sqSupplierBalances',1,N'dbo',NULL'
    • 如果您在 SSMS 中以图表形式看到执行计划,您可以通过打开属性 (F4) 找到参数值。详情:mssqltips.com/sqlservertip/4992/…
    猜你喜欢
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 2016-09-11
    • 1970-01-01
    相关资源
    最近更新 更多