嗨,我有以下动态存储过程,该过程最后返回一个正常结果集,但是Crystal报表未返回任何字段,任何人都可能知道哪里出了问题。
当我在工作室管理中运行proc时,它工作正常。这是使用树液版本的水晶的报告,以防有所不同。
我通常将结果输出到excel,并且可以正常运行,但是对于crystal来说,它不允许我在字段浏览器中选择任何字段。
ALTER PROCEDURE [dbo].[ReportByDates]
@DateFrom date NULL,
@DateTo date NULL
AS
SET NOCOUNT ON;
DECLARE @DynamicColumnsDivision AS VARCHAR(max)
DECLARE @DynamicColumnsDivision2 AS VARCHAR(max)
DECLARE @DynamicColumnsDivisionTotal AS VARCHAR(max)
SELECT @DynamicColumnsDivision = COALESCE(@DynamicColumnsDivision + ', ', '')
+ 'ISNULL(' +Quotename(fieldname) + ',0) as ' + Quotename(fieldname)
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'Division'
) AS FieldList
SELECT @DynamicColumnsDivision2 = COALESCE(@DynamicColumnsDivision2 + ', ', '')
+ Quotename(fieldname)
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'Division'
) AS FieldList
SELECT @DynamicColumnsDivisionTotal = COALESCE(@DynamicColumnsDivisionTotal + '+', '')
+ 'ISNULL(' +Quotename(fieldname) + ',0)'
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'Division'
) AS FieldList
DECLARE @DynamicColumnsGQO AS VARCHAR(max)
DECLARE @DynamicColumnsGQO2 AS VARCHAR(max)
DECLARE @DynamicColumnsGQOTotal as VARCHAR(max)
SELECT @DynamicColumnsGQO = COALESCE(@DynamicColumnsGQO + ', ', '')
+ 'ISNULL(' +Quotename(fieldname) + ',0) as ' + Quotename(fieldname)
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'GQO'
) AS FieldList
SELECT @DynamicColumnsGQO2 = COALESCE(@DynamicColumnsGQO2 + ', ', '')
+ Quotename(fieldname)
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'GQO'
) AS FieldList
SELECT @DynamicColumnsGQOTotal = COALESCE(@DynamicColumnsGQOTotal + '+', '')
+ 'ISNULL(' +Quotename(fieldname) + ',0)'
FROM (
SELECT
DISTINCT
PrcCode + ' - ' + cc.PrcName as fieldname
FROM OPRC cc
WHERE Active = 'Y' AND CCTypeCode = 'GQO'
) AS FieldList
DECLARE @Query NVARCHAR(MAX)
SET @Query =
'SELECT Account, AcctName, ' + @DynamicColumnsDivision + ', ' + @DynamicColumnsDivisionTotal + ' as DivisionTotal , ' + @DynamicColumnsGQO + ', ' + @DynamicColumnsGQOTotal + ' as GQOToatl
FROM
(
SELECT
line.Account,
nom.AcctName,
line.ProfitCode + '' - '' + cc.PrcName as fieldname,
CASE WHEN line.Debit <> 0 THEN line.Debit *-1 WHEN line.Credit <> 0 THEN line.Credit ELSE 0 END as DispValue
FROM OJDT head
LEFT JOIN JDT1 line on head.TransId = line.TransId
LEFT JOIN OACT nom on line.Account = nom.AcctCode
LEFT JOIN OPRC cc ON line.ProfitCode = cc.PrcCode
WHERE head.RefDate BETWEEN ''' + CONVERT(VARCHAR(10),@DateFrom, 101) + ''' AND ''' + CONVERT(VARCHAR(10),@DateTo, 101) + '''
) AS SourceTable PIVOT
(
SUM(DispValue)
FOR fieldname IN (' + @DynamicColumnsDivision2 + ', '+@DynamicColumnsGQO2 + ')
) AS PivotTable;
'
--SELECT @Query
execute(@Query)
编辑2 很奇怪,我复制了整个proc并声明了from和date到element的日期,并且效果很好。那么,为什么从存储的proc调用它时它可以正常工作。
答案 0 :(得分:0)
如果存储过程未返回任何数据,Crystal Reports将无法为您显示列。确保它返回了数据。
无论如何,您始终可以尝试删除存储过程,然后再次将其添加到数据库助手中。当您使用存储过程时,或者至少在较旧的版本中,Crystal Reports不能很好地更新字段。