When running a query in Visual Studio, TFS is building an SQL query for it. If you run SQL Server Profiler on the Tfs_DefaultCollection
database you should notice a similar query:
exec sp_executesql N'set nocount on
declare @PersonId as int
declare @rebuildOK as int
declare @PersonName as nvarchar(255)declare @userSid as nvarchar(256)
set @userSid=@P1
exec @rebuildOK=dbo.RebuildCallersViews @PersonId output,@P1
if @rebuildOK<>0 return
DECLARE @AsOfUtc DATETIME; SET @AsOfUtc=@P2
DECLARE @Ids TABLE (Id INT NOT NULL)
INSERT INTO @Ids SELECT X.ID FROM (
SELECT @P3 AS ID
UNION ALL
SELECT @P4 AS ID
) as X
join dbo.[WorkItemsLatestUsed] RL
on X.ID = RL.[System.Id]
where RL.[System.AreaID] not in
(
select V.BelowID
from dbo.[GetInverseUserPermissions](@userSid,1) V
)
option (loop join)
SELECT I.[System.Id],I.[System.Rev],I.[System.AreaId],I.[System.IterationId],I.[System.WorkItemType],I.[System.AssignedTo]
FROM @Ids Ids
JOIN [dbo].[WorkItemsAsOf] I with (nolock)
ON I.[System.Id] = Ids.[Id]
AND I.[System.ChangedDate] <= @AsOfUtc
AND @AsOfUtc < I.[System.RevisedDate]
OPTION (LOOP JOIN)
set nocount off
',N'@P1 nvarchar(4000),@P2 datetime,@P3 int,@P4 int',@P1=N'S-1-5-21-3698201826-3150490006-716737659-1107',@P2='2012-03-24 19:48:09.707',@P3=1266,@P4=1587
Note the use of dbo.RebuildCallersViews
stored procedure which in turn serves the @userSid
variable and ultimately the temporary I.[System.AssignedTo]
column. Stored procedures in TFS database are protected so I couldn't decipher what's going beyond that.