Sql 查看程序数据库查询和复制

Sql 查看程序数据库查询和复制,sql,powerbi,powerquery,Sql,Powerbi,Powerquery,我们有一个服务器,服务器上有一个数据库,上面有我们全部的财务记录,信息是通过一个名为MDA的财产管理程序获取的。MDA具有报告功能 是否可以查看程序查询数据库的具体内容,以便我可以在excel等中复制该特定报告表 MDA帮助页面确实给出了一些报告的sql代码,但不是全部,并且提供的一些代码没有给出相同的信息。那么,是否有可能从服务器端准确地看到正在做什么 编辑: 以下是捕获的查询: Update tmp Set tmp.TenantReceipts = a.

我们有一个服务器,服务器上有一个数据库,上面有我们全部的财务记录,信息是通过一个名为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 Server。 在这种情况下,考虑使用SQL探查器,因为它将允许捕获所有传入查询并提供执行统计信息,例如持续时间、IO和CPU成本等。 更新:

您提供的查询包含临时表和变量。 因此,还必须通过探查器跟踪临时表的创建。 当出现变量值时,可以通过跟踪事件Showplan XML统计配置文件找到它们

例如:

<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>

接下来,如果您的数据是通过Office数据网关来的,请考虑这一点:

问题:我如何查看向内部部署发送的查询 数据源

答:您可以启用查询跟踪。这将包括 正在发送的查询。记得把它改回原样 完成故障排除时的值。启用查询跟踪将 使日志变大


那么如果我想在PowerQuery中复制上面的查询,我可以输入变量值吗?对于最后一个表,我应该首先跟踪临时表,复制这些表,然后调整上面提供的查询以运行这些表?没错,必须跟踪序列的所有部分,包括临时表的创建。此外,变量将被替换为实际值。请澄清如何从Showplan XML Statistics Profile中获取参数列表,如您的示例所示。我已经添加了它,但它只提供了执行映射,而不像您的示例中那样提供了信息。之前运行的参数代码为“exec[MDAmanager]…sp_procedure_params_rowset N'sqSupplierBalances',1,N'dbo',NULL”。如果您将SSMS中的执行计划视为图表,则可以通过打开属性F4来查找参数值。细节: