SSRS - 目录为了将TOC提取到Word打印而打印

时间:2017-02-16 18:16:05

标签: sql-server reporting-services tableofcontents

我跟随这个帖子: Table of Contents for PDF/Printed Report in SSRS

我已经有了这两个SQL语句:

  • 用于存储报告数据的表(我在Report数据库中创建表):

    CREATE TABLE [dbo].[tbl_TOC](
    [RID] [int] IDENTITY(1,1) NOT NULL,
    [TOCExecutionID] [varchar](50) NULL,
    [AssessmentID] [int] NULL,
    [ReportName] [varchar](50) NULL,
    [GlobalsTotalPages] [int] NULL,
    [LoadDate] [datetime] NULL DEFAULT (getdate())
    ) ON [PRIMARY]
    
  • 我创建了商店程序:

    create proc rpt_dsTOC
    @TOCExecutionID varchar(50)
    as
    if OBJECT_ID('tempdb..#temp') is not null drop table #temp
    create table #temp (
        ord int NOT NULL,
        ReportName varchar(50) NULL,
        PageCnt int NULL,
        PageNo int null )
    
    ;with ctePageCount as (
    select distinct t.ReportName
        , t.GlobalsTotalPages PageCnt
        , t.TOCExecutionID
        , t.AssessmentID
    from        tbl_TOC t
    where        TOCExecutionID=@TOCExecutionID
    )
    insert into #temp
    select case when ReportName like 'Plan%' then 1  --List all of the          names of the subreports here
            when ReportName like 'Busin%' then 2
            when ReportName like 'Threa%' then 3
            when ReportName like '%Manag%' then 4
            when ReportName like '%Monit%' then 5
            when ReportName like 'Pande%' then 6
            when ReportName like 'Emerg%' then 7
            when ReportName like 'Key%' then 8
            when Reportname like 'Netw%' then 9
            else 10 end ord
        , ReportName
    , PageCnt
    , 0 PageNo
    from ctePageCount
    
  • 此部分使用每个部分中的总页数计算页面编号

    declare @run int = 3
    declare @ord int, @ReportName varchar(50), @PageCnt int, @PageNo int
    declare     c cursor for
        select    ord
        , ReportName
        , PageCnt
        , PageNo
    from #temp
    order by ord;
    open c
        fetch next from c into @ord, @ReportName, @PageCnt, @PageNo
        update #temp set PageNo=@run
        set @run = @run + @PageCnt--5
    while @@FETCH_STATUS = 0 --EOF
    begin
        fetch next from c into @ord, @ReportName, @PageCnt, @PageNo
        if @PageNo=0
        set @PageNo = @run
        update #temp set PageNo=@PageNo where ord=@ord 
        set @run = @PageNo + @PageCnt
    end
    close c
    deallocate c
    
    select * from #temp order by ord
    

但是我的表tbl_TOC如何加载报告详细信息?

谢谢!

1 个答案:

答案 0 :(得分:0)

哦 - 很抱歉!我忽略了一步。该DLL调用存储过程。 usp_LogReportAttributes

ALTER proc [dbo].[usp_LogReportAttributes] 
      @TOCExecutionID       VARCHAR(50)
    , @AssessmentID         int
    , @ReportName           VARCHAR(50)
    , @GlobalsTotalPages    INT

as
begin

delete from tbl_TOC where LoadDate<dateadd(day,-1,getdate())--just periodic maintenance so this table doesn't get too big

insert into tbl_TOC (
      TOCExecutionID
    , AssessmentID
    , ReportName
    , GlobalsTotalPages
)
--values (@TOCExecutionID, @AssessmentID, @ReportName,@GlobalsTotalPages)
select   @TOCExecutionID
       , @AssessmentID
       , @ReportName
       , @GlobalsTotalPages
where not exists (select 1 from tbl_TOC t where t.TOCExecutionID = @TOCExecutionID and t.ReportName = @ReportName)
end