【问题标题】:Having trouble with a SQL report for Dynamics CRMDynamics CRM 的 SQL 报告遇到问题
【发布时间】:2011-03-30 16:25:21
【问题描述】:

以下 SQL 代码创建了一个包含两行的表,其中一行是发票,另一行是分组付款。然而,这不是所需的表示。真正的目标是将其显示为报表,其中发票位于顶部,然后是按日期排序的付款列表。

是否可以根据显示的信息编写查询来完成此操作? (请随时索取更多信息)。任何人都可以提出一种方法吗?

这里是 SQL SELECT 代码:

SELECT     FilteredInvoice.accountidname,
           FilteredInvoice.createdon,
           FilteredInvoice.duedate,
           FilteredInvoice.invoicenumber,               
           FilteredInvoice.statecodename,
           FilteredInvoice.totalamount_base,
           FilteredMag_Payment.mag_paymentdate,
           FilteredMag_Payment.mag_amount_base,
           GETDATE() AS Today

FROM            FilteredInvoice
LEFT OUTER JOIN FilteredAccount ON FilteredInvoice.accountid = FilteredAccount.accountid
LEFT OUTER JOIN FilteredMag_Payment ON FilteredInvoice.invoiceid = FilteredMag_Payment.mag_invoiceid

WHERE     (FilteredInvoice.statecodename <> N'Canceled')
ORDER BY FilteredInvoice.createdon

【问题讨论】:

  • 是的,这是可能的——您当前的 SQL 是否达不到您的要求?
  • 目前它按发票日期排序,如果有付款,它将直接放在下面,因为我希望两者都按日期顺序排列。
  • 您真的为此使用 SSRS Tablix 吗?普通的SSRS表对象不是更有用吗?

标签: sql sql-server reporting-services dynamics-crm crm


【解决方案1】:

在我看来,付款信息应该与发票在同一行。您获得第二行的唯一方法是您有两次付款。由于您按发票日期排序,因此两行将具有相同的日期并彼此相邻排序。

根据您所说,我的猜测是,如果没有付款,您想按发票日期排序,如果有,则按付款日期排序。试试:

Order by Coalesce(FilteredMag_Payment.mag_paymentdate, FilteredInvoice.createdon)

【讨论】:

    【解决方案2】:

    原始查询有一些奇怪之处 - 帐户 ID 名称是否真的保存在 Invoice 表中,而不是 Account 表中?从 Invoice 到 Account 的左外连接也使得看起来好像存在没有相应 Accounts 的 Invoices - 假设相反会更正常,尤其是在报表报告中。

    假设原始查询正确选择了所需的数据,我建议:

    SELECT    FilteredInvoice.accountidname, 
        FilteredInvoice.createdon,
        FilteredInvoice.createdon AS sort_date,
        FilteredInvoice.duedate,
        FilteredInvoice.invoicenumber,
        FilteredInvoice.statecodename, 
        FilteredInvoice.totalamount_base,
        CONVERT(datetime,NULL) AS mag_paymentdate,
        0 AS mag_amount_base,
        GETDATE() AS Today
    FROM    FilteredInvoice 
    LEFT OUTER JOIN    FilteredAccount ON FilteredInvoice.accountid = FilteredAccount.accountid 
    WHERE    (FilteredInvoice.statecodename <> 'Canceled')
    UNION ALL
    SELECT    FilteredInvoice.accountidname, 
        FilteredInvoice.createdon,
        FilteredInvoice.createdon AS sort_date,
        FilteredInvoice.duedate,
        FilteredInvoice.invoicenumber,
        FilteredInvoice.statecodename, 
        FilteredInvoice.totalamount_base,
        FilteredMag_Payment.mag_paymentdate,
        FilteredMag_Payment.mag_amount_base,
        GETDATE() AS Today
    FROM    FilteredInvoice 
    LEFT OUTER JOIN    FilteredAccount ON FilteredInvoice.accountid = FilteredAccount.accountid 
    JOIN    FilteredMag_Payment ON FilteredInvoice.invoiceid = FilteredMag_Payment.mag_invoiceid
    WHERE    (FilteredInvoice.statecodename <> 'Canceled')
    ORDER BY 3
    

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多