需要此查询的结果:
SELECT CAST(a.InvoiceDate AS DATE) InvoiceDate,
COUNT(*) RecordCount
FROM SalesOrder a
JOIN IMSSalesExtractHistory b
ON a.SlsOrdNbr = b.SlsOrdNbr
AND a.OrdLnNbr = b.OrdLnNbr
AND a.OrdLnSeqNbr = b.OrdLnSeqNbr
WHERE b.SAFInsertDate > GETDATE()-2
GROUP BY CAST(a.InvoiceDate AS DATE)
ORDER BY CAST(a.InvoiceDate AS DATE)
将被复制到我的Crystal Report中。
我已在Crystal Reports 2013中的Formula Workshop窗口中启动此公式,但它一直给我这个错误:
(
SELECT DISTINCT CAST("SalesOrder"."InvoiceDate" AS DATE) InvoiceDate
FROM "SalesOrder"
JOIN "IMSSalesExtractHistory"
ON "SalesOrder"."SlsOrdNbr" = "IMSSalesExtractHistory"."SlsOrdNbr"
AND "SalesOrder"."OrdLnNbr" = "IMSSalesExtractHistory"."OrdLnNbr"
AND "SalesOrder"."OrdLnSeqNbr" = "IMSSalesExtractHistory"."OrdLnSeqNbr"
WHERE "IMSSalesExtractHistory"."FileDate" > {fn CURDATE()}
)
错误:
编译SQL表达式时出错: 无法从数据库中检索数据。 详细信息:ADO错误代码:0x80040e07 来源:用于SQL Server的Microsoft OLE DB提供程序 说明:转换varchar值时转换失败' 2016-05-25'到数据类型int。 SQL状态:22018
我从CS查询中删除了COUNT(*)因为我在工作时会使用相同的代码,并在报告中找到新列的计数。
寻找有人帮助转换初始SQL查询,以便它在Crystal Reports中没有错误。
编辑: 作为参考,这是我在Crystal Report中需要的结果集,我从上面的SQL脚本生成。
InvoiceDate RecordCount
2016-05-13 16074
2016-05-14 2
2016-05-15 4
2016-05-16 27495
2016-05-17 20023
2016-05-18 18923
2016-05-19 18944
答案 0 :(得分:1)
启动水晶报告并建立数据库连接。
而不是选择表格选择add command
并粘贴此查询
SELECT CAST(a.InvoiceDate AS DATE) InvoiceDate,
COUNT(*) RecordCount
FROM SalesOrder a
JOIN IMSSalesExtractHistory b
ON a.SlsOrdNbr = b.SlsOrdNbr
AND a.OrdLnNbr = b.OrdLnNbr
AND a.OrdLnSeqNbr = b.OrdLnSeqNbr
WHERE b.SAFInsertDate > GETDATE()-2
GROUP BY CAST(a.InvoiceDate AS DATE)
ORDER BY CAST(a.InvoiceDate AS DATE)
现在必须设计并将所需的列放在详细信息中。