嗨所有这一切都将是一个非常奇怪的问题,我所有的搜索都没有得到很好的答案。基本问题将帮助我解决Crystal Reports中的两个问题和SSRS 2005中的一个问题。我的报告都需要相同类型的解决方案。请耐心等待,因为解释会有点冗长。
我需要以不寻常的方式使用SSRS。我需要创建的报告只有最少的数据,将在现场手工打印和填写。在这种情况下,它们被用作表格打印程序。
报告将对它们进行tablix / Matrix控制,我需要使用特定的#列创建它,无论这些列是否存在数据。在一种情况下(SSRS),没有字段被用作将要求和的数据字段。
我有行和列的数据,但我需要的是创建10列的矩阵/ tablix。因此,如果记录集只有2个数据实例将构成列,我仍然希望看到所有10列,但标题是空白的。
所以它看起来像这样:
Col1|Col2|Col3|Fake1|Fake2|Fake3|......
Row1
Row2
Row3
.....
因此,如果我有1列或10列数据,我仍然希望显示10列2列有真正的标题,8列带有空白标题。
这是我正在使用的SQL。这是SSRS 2005中矩阵的基础。员工ID和名称是行。 JobAccount_Tracking_ID是列。 记录可以包含1到10个tracking_ids。
我想要返回的是总共10个跟踪ID,而不管实际的跟踪ID数量。附加内容将在矩阵中显示为空白列。
Declare @FieldLogID as int
Set @FieldLogID = 1018
SELECT DISTINCT
CustomizedFieldLogEmployee_1.Employee_EmployeeID,
CustomizedFieldLogEmployee_1.Employee_FullName,
CustomizedFieldLogEmployee_1.Injured_Today_Custom,
CustomizedFieldLogJobAccount_1.JobAccount_TrackingID,
CustomizedFieldLogEmployee_1.StartDateTime,
CustomizedFieldLogEmployee_1.StopDateTime,
CustomizedFieldLogEmployee_1.WorkHours
FROM
CustomizedFieldLogEmployee AS CustomizedFieldLogEmployee_1 LEFT OUTER JOIN CustomizedFieldLogJobAccount AS CustomizedFieldLogJobAccount_1
ON CustomizedFieldLogEmployee_1.FieldLog_FieldLogID = CustomizedFieldLogJobAccount_1.FieldLog_FieldLogID
WHERE CustomizedFieldLogEmployee_1.FieldLog_FieldLogID = @FieldLogID
我有什么想法可以做到这一点?在SSRS的情况下,我无法在数据库中创建视图,因为它是供应商的数据库。
答案 0 :(得分:0)
所以这是逻辑:
这是代码:
Declare @FieldLogID as int
Set @FieldLogID = 1018
Select Employee_EmployeeID,
Employee_FullName,
Injured_Today_Custom,
Case when JobAccount_TrackingID like'zzz%' then Null else JobAccount_TrackingID end as JobAccount_TrackingID,
StartDateTime,
StopDateTime,
WorkHours
from
(
Select row_number() over (partition by Employee_EmployeeID order by JobAccount_TrackingID) row,*
from
(
SELECT DISTINCT
CustomizedFieldLogEmployee_1.Employee_EmployeeID,
CustomizedFieldLogEmployee_1.Employee_FullName,
CustomizedFieldLogEmployee_1.Injured_Today_Custom,
CustomizedFieldLogJobAccount_1.JobAccount_TrackingID,
CustomizedFieldLogEmployee_1.StartDateTime,
CustomizedFieldLogEmployee_1.StopDateTime,
CustomizedFieldLogEmployee_1.WorkHours
FROM
CustomizedFieldLogEmployee AS CustomizedFieldLogEmployee_1 LEFT OUTER JOIN CustomizedFieldLogJobAccount AS CustomizedFieldLogJobAccount_1
ON CustomizedFieldLogEmployee_1.FieldLog_FieldLogID = CustomizedFieldLogJobAccount_1.FieldLog_FieldLogID
WHERE CustomizedFieldLogEmployee_1.FieldLog_FieldLogID = @FieldLogID
Union
Select Distinct
Employee_EmployeeID,
Employee_FullName,
null as Injured_Today_Custom,
fake_TrackingID,
null as StartDateTime,
null as StopDateTime,
null as WorkHours
FROM
CustomizedFieldLogEmployee
cross join
(
Select 'zzz01' fake_TrackingID
union Select 'zzz02'
union Select 'zzz03'
union Select 'zzz04'
union Select 'zzz05'
union Select 'zzz06'
union Select 'zzz07'
union Select 'zzz08'
union Select 'zzz09'
union Select 'zzz10'
) a where FieldLog_FieldLogID = @FieldLogID
) b
) c where Row<=10
order by Employee_EmployeeID,JobAccount_TrackingID