2011-01-18 9 views
10

Mi è stato chiesto un paio di volte di modificare dinamicamente il nome del file in SSRS 2008. Esempio: ReportName_201101.RDL. Il 201101 rappresenta la data di esecuzione. Questo può essere realizzato in SSRS 2008?Creare dinamicamente il nome file in SSRS 2008

risposta

1

Sfortunatamente no, non è possibile. È un'altra di quelle funzionalità che manca a SSRS che gli sviluppatori hanno richiesto.

6

Se si intende il nome file quando si esporta il report ed è anche possibile estrarlo dal ReportViewer di ASP.NET, è possibile impostare il nome tramite la proprietà DisplayName.

ReportViewerControl.ServerReport.DisplayName = "ReportName_201101"; 

o (se ProcessingMode è locale):

ReportViewerControl.LocalReport.DisplayName = "ReportName_201101"; 

per praticamente tutti gli altri casi, Alison è giusto.

+0

Questo è quello che sto cercando, grazie per questo. – user2705620

2

C'è uno MS Connect item aperto per questo. Ha solo pochi voti, quindi andate là e spostatelo di nuovo ...

2

Un altro problema è rinominare il report prima che venga eseguito automaticamente. Questo è un diamante grezzo. Questo può funzionare solo per i report che sono abbonamenti e non quelli a cui gli utenti rimandano. Creare una tabella nel database ReportServer che contiene un elenco di tutti i report che si desidera rinominare prima dell'esecuzione. Tabella Report_Rename_Listing RenameID int ItemID uniqueidentifier OriginalReportName nvarchar (350) DateType nvarchar (75) Format int DatePlusMinus reale Creare una stored procedure sullo stesso server che si spegne e cambia tutti i rapporti nella tabella sopra riportata.

Create Procedure [dbo].[RenameReports] 
AS 
SET NOCOUNT OFF ; 
    Update dbo.Catalog 
    Set Name = ISNULL((Select OriginalReportName + '_' + 
       dbo.func_SetupRenameOfReports(DateType, Format, DatePlusMinus) 
     From dbo.DDC_Report_Rename r 
     Where r.ItemID = c.ItemID), Name) 
    From dbo.Catalog c 
return (0) 

Creare una funzione scalare sullo stesso server che capisce solo come si desidera rinominare il report.

Create Function [dbo].[func_SetupRenameOfReports] 
(@DateType nvarchar(75), @Format int, @PlusMinus real ) 
RETURNS nvarchar(75) 
AS 
BEGIN 
    Declare @FirstMonth datetime, @LastMonth datetime 
    Declare @OutputFormat nvarchar(75) 

    Set @FirstMonth = CONVERT(datetime, Convert(varchar(2), DateAdd(mm, @PlusMinus, GetDate()), 103) + '/1/' + CONVERT(varchar(4), DateAdd(mm, @PlusMinus, GetDate()), 102)) 
    Set @LastMonth = DATEADD(dd, -1, DateAdd(mm, 1, @FirstMonth)) 

    Set @OutputFormat = 
    Case When @DateType = 'CurrentDate' Then Convert(varchar(75), DateAdd(dd, @PlusMinus, GetDate()), @Format) 
     When @DateType = 'CurrentDayName' Then CONVERT(varchar(75), DateName(dw, DateAdd(dd, @PlusMinus, GetDate()))) 
     When @DateType = 'CurrentMonthName' Then CONVERT(varchar(75), DateName(mm, DateAdd(mm, @PlusMinus, GetDate()))) 
     When @DateType = 'CurrentYear' Then CONVERT(varchar(75), DateAdd(yy, @PlusMinus, GetDate())) 
     When @DateType = 'CurrentBeginEndMonth' Then CONVERT(varchar(10), @FirstMonth, @Format) + '-' + CONVERT(varchar(10), @LastMonth, @Format) 
    End 

    If @OutputFormat IS null 
    Begin 
     Set @OutputFormat = '' 
    End 
Return @OutputFormat 

END 

Quindi configurare questa opzione affinché la stored procedure venga eseguita automaticamente ogni giorno sul server. Lo faccio girare subito dopo mezzanotte tutti i giorni.

1

Ecco una correzione alla procedura memorizzata sopra in modo che funzioni effettivamente.

ALTER PROCEDURE [dbo].[ddc_RenameReports] 

AS 
SET NOCOUNT OFF ; 

    Update dbo.Catalog 
    Set Name = ISNULL((Select OriginalReportName + '_' + 
       dbo.func_SetupRenameOfReports(DateType, Format, DatePlusMinus) 
     From dbo.DDC_Report_Rename r 
     Where r.ItemID = c.ItemID And r.Active = 1), Name) 
    From dbo.Catalog c 
    Update c 
    Set c.Path = ISNULL((Select c2.Path + '/' + OriginalReportName + '_' + 
       dbo.func_SetupRenameOfReports(DateType, Format, DatePlusMinus) 
      From dbo.DDC_Report_Rename r2 
      Where r2.ItemID = c.ItemID AND r2.Active = 1), c.Path)  
    From dbo.Catalog c 
    inner join dbo.Catalog c2 on c2.ItemID = c.ParentID 
return (0) 
Problemi correlati