Ravendra's Blog

June 1, 2010

TFS Reports on Attachments and Long Text


Reporting on Attachments and long text fields are not supported by Team foundation server (even up to latest TFS 2010). In case you need to report on fields of type Attachment and Long text then you need to directly query TFS project collection database.

Attachments are stored at [dbo].[Attachments] table.

Following Query can be helpful to extract actual attachment content.

Create procedure [dbo].[GetWeeklyUpdateAttachment]

@projectName as
				varchar(256)

as

begin

declare @SQL nvarchar(4000),

        @ReportFrom nvarchar (100),

        @ReportTo nvarchar (100)

 

select @ReportFrom=ColName from Fields where name ='ReportFrom'

select @ReportTo=ColName from Fields where name ='ReportTo'

 

select @SQL =
				'Select top 1 [FileId]

      ,[FileGuid]

      ,[FileContent]

      ,[IdentityName]

      ,[ProjectUri]

  FROM [dbo].[Attachments] at

 inner join dbo.WorkItemFiles f on at.FileGuid = f.FilePath

 where f.RemovedDate = @MaxDate

 and f.Id = (select top 1 b.ID from 

    WorkItemsAre b 

    inner join xxTree a  on a.ID = b.AreaID

    WHERE    a.[Team Project] = @projectName2 

         and b.[Work Item Type] = @TypeName

        order by '
				+ @ReportTo +
				' desc)'

 

Exec
				sp_executesql
				@SQL,
				N'@TypeName nVarChar(100),@projectName2 nVarChar(100), @MaxDate datetime', @TypeName =
				'Weekly Project Update',  @projectName2 = @projectName, @MaxDate =
				'9999-01-01 00:00:00.000'

 

End

 

Long text are stored at [dbo].[WorkItemLongTexts] table

Following Query may be customized to find exact description field, Value of FldID need to be modified by field id of your description field.

 

Create PROCEDURE [dbo].[GetWeeklyProjectUpdateDescription]

    @projectName as
				nvarchar(256)
			

AS

BEGIN

    SET
				NOCOUNT
				ON;

 

declare @SQL nvarchar(4000),

        @ReportFrom nvarchar (100),

        @ReportTo nvarchar (100)

,@NextMilestone1 nvarchar(200)

 

select @ReportFrom=ColName from Fields where name ='ReportFrom'

select @ReportTo=ColName from Fields where name ='ReportTo'

 

select @SQL =
				'Select top 1 WORDS 

FROM WorkItemLongTexts l

WHERE    FldID = 52

    and l.ID = (select top 1 b.Id from 

    WorkItemsAre b 

    JOIN xxTree a on a.ID = b.AreaID

        and a.[Team Project] = @projectName2 

         and b.[Work Item Type] = @TypeName

        order by '
				+ @ReportTo +
				' desc)

        order by AddedDate desc'

 

Exec
				sp_executesql
				@SQL,
				N'@TypeName nVarChar(100),@projectName2 nVarChar(100)', @TypeName =
				'Weekly Project Update',  @projectName2 = @projectName

 

END

Blog at WordPress.com.