简体   繁体   English

SSRS:来自数据集的参数填充

[英]SSRS: Parameter population from a dataset

I have a dataset with start dates, end dates, and term codes. 我有一个包含开始日期,结束日期和术语代码的数据集。 The user will enter in an academic year. 用户将输入一个学年。 The academic year will be used to determine the three term codes for that year. 该学年将用于确定该年的三个学期代码。 I want to use those three codes to select start and end dates for each term, which will go into the main query. 我想使用这三个代码为每个术语选择开始和结束日期,这将进入主查询。 I can achieve this by setting up three datasets that will hold the term code, start date, and end date for each term and populating the start and end date parameters from there, but what I want to know is if there is a more dynamic way to achieve this. 我可以通过设置三个包含每个术语的术语代码,开始日期和结束日期的数据集并从那里填充开始和结束日期参数来实现这一点,但是我想知道的是,是否还有一种更动态的方式为达到这个。

Thanks! 谢谢!

Some clarification. 一些澄清。 I want a way to populate all six parameters from one dataset, not each start and end date getting its own dataset. 我想要一种从一个数据集中填充所有六个参数的方法,而不是每个开始和结束日期都获得其自己的数据集。

I can't be sure of how your data is set up, so I'm going to make a few guesses here. 我不确定您的数据是如何设置的,因此在这里我会做一些猜测。 You can return six separate dates by pivoting the Start and End Dates for each Term: 您可以通过旋转每个术语的开始日期和结束日期来返回六个单独的日期:

declare @TermCodes table(AcademicYear int,TermCode varchar(50))
insert into @TermCodes
    values
        (2014,'FL14'),
        (2014,'SP14'),
        (2014,'SM14')

declare @TermDates table(TermCode varchar(50), StartDate date,EndDate date)
insert into @TermDates
    values
        ('FL14','20140915','20141215'),
        ('SP14','20150115','20150415'),
        ('SM14','20150515','20150815')

declare @AcademicYear int
set @AcademicYear = 2014

select
    min(StartDate1) StartDate1,
    min(EndDate1) EndDate1,
    min(StartDate2) StartDate2,
    min(EndDate2) EndDate2,
    min(StartDate3) StartDate3,
    min(EndDate3) EndDate3
from    (
        select
            td.StartDate,
            td.EndDate,
            'StartDate' + cast(row_number() over(order by td.StartDate) as char(1)) StartDates,
            'EndDate' + cast(row_number() over(order by td.StartDate) as char(1)) EndDates
        from @TermCodes tc
            inner join @TermDates td
                on td.TermCode = tc.TermCode
        where tc.AcademicYear = @AcademicYear
        ) t
    pivot   (
            max(StartDate)
            for StartDates in(StartDate1,StartDate2,StartDate3)
            ) sd
    pivot   (
            max(EndDate)
            for EndDates in(EndDate1,EndDate2,EndDate3)
            ) ed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM