我做了一个动态的 pivot sql 查询来获得类似的结果,
为此,我的查询如下,
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(AssortmentSize)
from tbl_Assortment_Qty WHERE Head_Id=325
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query='SELECT Description,AssortmentType, '+@cols+',ISNULL (size_unit_price,0) UnitPrice from
(
SELECT DISTINCT H.Description,AssortmentType,AssortmentSize,AssortmentQty,B.size_unit_price FROM dbo.tbl_Assortment_Qty Q
INNER JOIN
dbo.tbl_Fabric_Order_Head H
ON H.Head_ID=Q.Head_ID
LEFT OUTER JOIN
dbo.Budget_Accessories_Qty B
ON B.head_Id=Q.Head_Id
AND B.accessories=Q.AssortmentType
WHERE Q.head_id=325
) x
pivot
(
SUM(AssortmentQty)
for AssortmentSize in (' + @cols + ')
) p '
execute(@query)
现在我想将结果数据表直接打印到水晶报表中。我想要它原样,标题名称完好无损。现在我完全陷入了困境。我无法定义水晶报表中固定的列,因为它们是动态的。尺码 c(L,M,S,XL) 可能是其他尺码,我不是水晶报告专家。我需要的最简单的答案是,如何将 DATATABLE 直接打印到 Crystal 报表中,而不定义其列字段?