SQL query to find all suites that are associated with automation

I trying to incorporate CodeUI tests into a Release Mangement deployment template ... As a developer, I want to be able to specify a sub-tree of a test plan & only execute those test suites that are associated with automation.  Is there a way to
extract all automated workitems and associated them with their respective test suites?
Any assistance would be greatly appreciated!

John,
I've partially resolved the issue of executing a sub-set of suites with the following powershell implementation:
1. Extract "potential" suite paths from a XML configuration file:
<?xml version="1.0"?>
<Configurations>
<Properties>
<Property key="DEFAULT" value="SuitePaths" />
<Property key="DatabaseServer" value="MYDBSERVER" />
<Property key="DatabaseInstance" value="Default" />
<Property key="DatabaseName" value="TFS_DefaultCollection" />
<Property key="ConfigurationName" value="US - Windows 7 and IE 10" />
</Properties>
<Notifications>
<Notification key="0" value="[email protected]" />
</Notifications>
<SuitePaths>
<SuitePath key="0" value="MyProject\WebProduct\Student\Features\Login" />
<SuitePath key="1" value="MyProject\WebProduct\Student\Features\Logout" />
</SuitePaths>
<AreaPaths>
<AreaPath key="0" value="MyProject\WebProduct\Student\Features\Login" />
</AreaPaths>
</Configurations>
2. Extract record set of suites from TFS via SQL query:
# FUNCTION: Retrieve-SuitePaths
# Parameters:
# (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
# (2.) Connection -- Database connection
# (3.) Paths -- Hash table of suite paths
Function Retrieve-SuitePaths
param
[Parameter(Mandatory=$True)][String]$LogFile,
[Parameter(Mandatory=$True)]$Connection,
[Parameter(Mandatory=$True)]$Paths
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output "Retrieve suite(s): " | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
$SuitePaths = "("
$Counter = 0
foreach ($Key in $Paths.Keys)
if ($Counter -gt 0)
$SuitePaths = $SuitePaths + ", "
$SuitePaths = $SuitePaths + "'" + $Paths.Get_Item($Key) + "'"
$Counter += 1
$SuitePaths = $SuitePaths + ")"
# --DEBUG ONLY--> Write-Output "Paths: $SuitePaths" | Out-File -FilePath $LogFile -Append
$Command = New-Object System.Data.SqlClient.SqlCommand
$SQLStatement = "
WITH
cte_SuiteChildren
AS
-- Anchor definition to pull all certify modes
SELECT
S.[SuiteId],
S.[ProjectId],
PJ.ProjectName,
S.[PlanId],
P.[Name] AS PlanName,
S.[ParentSuiteId],
S.[SuitePath],
CONVERT(NVARCHAR(256), NULL) AS ParentTitle,
S.[Title],
0 AS RecurseLevel
FROM
[dbo].[tbl_Suite] AS S
INNER JOIN [dbo].[tbl_Plan] AS P ON S.PlanID = P.PlanID
INNER JOIN [dbo].[tbl_Project] AS PJ ON S.ProjectID = PJ.ProjectID
WHERE
S.ParentSuiteID = 0
UNION ALL
-- Recursive member to pull details of certify sessions
SELECT
S.[SuiteId],
S.[ProjectId],
PJ.ProjectName,
S.[PlanId],
P.[Name] AS PlanName,
S.[ParentSuiteId],
S.[SuitePath],
PS.[Title] AS ParentTitle,
S.[Title],
SC.[RecurseLevel] + 1 AS RecurseLevel
FROM
[dbo].[tbl_Suite] AS S
INNER JOIN cte_SuiteChildren AS SC on SC.SuiteID = S.ParentSuiteID
INNER JOIN [dbo].[tbl_Suite] AS PS ON SC.SuiteId = PS.SuiteId
INNER JOIN [dbo].[tbl_Plan] AS P ON S.PlanID = P.PlanID
INNER JOIN [dbo].[tbl_Project] AS PJ ON S.ProjectID = PJ.ProjectID
cte_SuiteLevel_0
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[ProjectName] + '\' + SC.[PlanName] AS Path,
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 0
cte_SuiteLevel_1
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 1
cte_SuiteLevel_2
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 2
cte_SuiteLevel_3
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 3
cte_SuiteLevel_4
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 4
cte_SuiteLevel_5
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 5
cte_SuiteLevel_6
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 6
cte_SuiteLevel_7
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 7
cte_SuiteLevel_8
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 8
cte_SuiteLevel_9
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 9
cte_SuiteLevel_10
AS
SELECT
SC.[ProjectId],
SC.[PlanId],
SC.[ParentSuiteId],
SC.[SuiteId],
SC.[ProjectName],
SC.[PlanName],
SC.[Title],
SC.[RecurseLevel]
FROM
cte_SuiteChildren AS SC
WHERE
SC.[RecurseLevel] = 10
cte_Suites
AS
SELECT
SL0.[ProjectId],
SL0.[PlanId],
CASE
WHEN SL2.ParentSuiteId IS NULL
THEN SL1.ParentSuiteId
ELSE CASE
WHEN SL3.ParentSuiteId IS NULL
THEN SL2.ParentSuiteId
ELSE CASE
WHEN SL4.ParentSuiteId IS NULL
THEN SL3.ParentSuiteId
ELSE CASE
WHEN SL5.ParentSuiteId IS NULL
THEN SL4.ParentSuiteId
ELSE CASE
WHEN SL6.ParentSuiteId IS NULL
THEN SL5.ParentSuiteId
ELSE CASE
WHEN SL7.ParentSuiteId IS NULL
THEN SL6.ParentSuiteId
ELSE CASE
WHEN SL8.ParentSuiteId IS NULL
THEN SL7.ParentSuiteId
ELSE CASE
WHEN SL9.ParentSuiteId IS NULL
THEN SL8.ParentSuiteId
ELSE CASE
WHEN SL10.ParentSuiteId IS NULL
THEN SL9.ParentSuiteId
ELSE SL10.ParentSuiteId
END
END
END
END
END
END
END
END
END AS [ParentSuiteId],
CASE
WHEN SL2.SuiteId IS NULL
THEN SL1.SuiteId
ELSE CASE
WHEN SL3.SuiteId IS NULL
THEN SL2.SuiteId
ELSE CASE
WHEN SL4.SuiteId IS NULL
THEN SL3.SuiteId
ELSE CASE
WHEN SL5.SuiteId IS NULL
THEN SL4.SuiteId
ELSE CASE
WHEN SL6.SuiteId IS NULL
THEN SL5.SuiteId
ELSE CASE
WHEN SL7.SuiteId IS NULL
THEN SL6.SuiteId
ELSE CASE
WHEN SL8.SuiteId IS NULL
THEN SL7.SuiteId
ELSE CASE
WHEN SL9.SuiteId IS NULL
THEN SL8.SuiteId
ELSE CASE
WHEN SL10.SuiteId IS NULL
THEN SL9.SuiteId
ELSE SL10.SuiteId
END
END
END
END
END
END
END
END
END AS [SuiteId],
SL0.ProjectName,
SL0.PlanName,
--SL0.Path,
--SL1.[Title],
CASE
WHEN SL2.Title IS NULL
THEN SL0.Path + '\' + SL1.Title
ELSE CASE
WHEN SL3.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title
ELSE CASE
WHEN SL4.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title
ELSE CASE
WHEN SL5.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title
ELSE CASE
WHEN SL6.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title
ELSE CASE
WHEN SL7.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title
ELSE CASE
WHEN SL8.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title
ELSE CASE
WHEN SL9.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title
ELSE CASE
WHEN SL10.Title IS NULL
THEN SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title + '\' + SL9.Title
ELSE SL0.Path + '\' + SL1.Title + '\' + SL2.Title + '\' + SL3.Title + '\' + SL4.Title + '\' + SL5.Title + '\' + SL6.Title + '\' + SL7.Title + '\' + SL8.Title + '\' + SL9.Title + '\' + SL10.Title
END
END
END
END
END
END
END
END
END AS Path,
CASE
WHEN SL2.RecurseLevel IS NULL
THEN SL1.RecurseLevel
ELSE CASE
WHEN SL3.RecurseLevel IS NULL
THEN SL2.RecurseLevel
ELSE CASE
WHEN SL4.RecurseLevel IS NULL
THEN SL3.RecurseLevel
ELSE CASE
WHEN SL5.RecurseLevel IS NULL
THEN SL4.RecurseLevel
ELSE CASE
WHEN SL6.RecurseLevel IS NULL
THEN SL5.RecurseLevel
ELSE CASE
WHEN SL7.RecurseLevel IS NULL
THEN SL6.RecurseLevel
ELSE CASE
WHEN SL8.RecurseLevel IS NULL
THEN SL7.RecurseLevel
ELSE CASE
WHEN SL9.RecurseLevel IS NULL
THEN SL8.RecurseLevel
ELSE CASE
WHEN SL10.RecurseLevel IS NULL
THEN SL9.RecurseLevel
ELSE SL10.RecurseLevel
END
END
END
END
END
END
END
END
END AS RecurseLevel
FROM
cte_SuiteLevel_0 AS SL0
LEFT OUTER JOIN cte_SuiteLevel_1 AS SL1 ON SL1.ParentSuiteId = SL0.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_2 AS SL2 ON SL2.ParentSuiteId = SL1.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_3 AS SL3 ON SL3.ParentSuiteId = SL2.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_4 AS SL4 ON SL4.ParentSuiteId = SL3.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_5 AS SL5 ON SL5.ParentSuiteId = SL4.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_6 AS SL6 ON SL6.ParentSuiteId = SL5.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_7 AS SL7 ON SL7.ParentSuiteId = SL6.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_8 AS SL8 ON SL8.ParentSuiteId = SL7.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_9 AS SL9 ON SL9.ParentSuiteId = SL8.SuiteId
LEFT OUTER JOIN cte_SuiteLevel_10 AS SL10 ON SL10.ParentSuiteId = SL9.SuiteId
SELECT
SS.[ProjectId],
SS.[PlanId],
SS.[ParentSuiteId],
SS.[SuiteId],
SS.[ProjectName],
SS.[PlanName],
SS.[Path],
SS.[RecurseLevel]
FROM
SELECT DISTINCT
S.[ProjectId],
S.[PlanId],
S.[ParentSuiteId],
S.[SuiteId],
S.[ProjectName],
S.[PlanName],
S.[Path],
S.[RecurseLevel]
FROM
cte_Suites AS S
WHERE
S.[RecurseLevel] IS NOT NULL
AND S.[Path] IN $($SuitePaths)
) AS SS
ORDER BY
SS.[Path]
$Command.CommandText = $SQLStatement
$Command.Connection = $Connection
$Command.CommandTimeout = 240
$DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$DataAdapter.SelectCommand = $Command
$DataSet = New-Object System.Data.DataSet
$DataAdapter.Fill($DataSet) | Out-Null
Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
# --DEBUG ONLY--> $DataSet.Tables[0]
return $DataSet
3. Execute every suite in the record set via TCM
$DataSet = ( Retrieve-SuitePaths -LogFile:$LogFile -Connection:$Connection -Path:$Paths)
# --DEBUG ONLY--> $DataSet.Tables[0].Rows.Count
# --DEBUG ONLY--> $DataSet.Tables[0]
# Determine whether or not any test suites were retrieved from TFS....
if ( $DataSet.Tables[0].Rows.Count -gt 0 )
$ListTestRunID = $null
$SumFailed = 0
$SumInconclusive = 0
foreach ($Row in $DataSet.Tables[0].Rows)
# Set project, plan & suite variables....
[Int16]$ProjectID = $Row.Item('ProjectId')
[Int16]$PlanID = $Row.Item('PlanId')
[Int16]$ParentSuiteID = $Row.Item('ParentSuiteId')
[Int16]$SuiteID = $Row.Item('SuiteId')
$ProjectName = $Row.Item('ProjectName')
$PlanName = $Row.Item('PlanName')
$Path = $Row.Item('Path')
$RecurseLevel = $Row.Item('RecurseLevel')
# Set local build path variable....
switch -wildcard ($Path)
"*WebCMS*\Administration\*"
$CUITBuildPath = $CUITPathUNC + '\WebCMS\Administration'
"*WebCMS*\Instructor\*"
$CUITBuildPath = $CUITPathUNC + '\WebCMS\Instructor'
"*WebCMS*\Student\*"
$CUITBuildPath = $CUITPathUNC + '\WebCMS\Student'
"*WebProduct*\Instructor\*"
$CUITBuildPath = $CUITPathUNC + '\WebProduct\Instructor'
"*WebProduct*\Student\*"
$CUITBuildPath = $CUITPathUNC + '\WebProduct\Student'
default
$CUITBuildPath = $CUITPathUNC
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output 'Test Suite:' | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output " ID:" | Out-File -FilePath $LogFile -Append
Write-Output " Project: $ProjectID" | Out-File -FilePath $LogFile -Append
Write-Output " Plan: $PlanID" | Out-File -FilePath $LogFile -Append
Write-Output " Parent Suite: $ParentSuiteID" | Out-File -FilePath $LogFile -Append
Write-Output " Suite: $SuiteID" | Out-File -FilePath $LogFile -Append
Write-Output " Config: $ConfigurationID" | Out-File -FilePath $LogFile -Append
Write-Output " Name:" | Out-File -FilePath $LogFile -Append
Write-Output " Project: $ProjectName" | Out-File -FilePath $LogFile -Append
Write-Output " Plan: $PlanName" | Out-File -FilePath $LogFile -Append
Write-Output " Config: $ConfigurationName" | Out-File -FilePath $LogFile -Append
Write-Output " Path:" | Out-File -FilePath $LogFile -Append
Write-Output " Suite: $Path" | Out-File -FilePath $LogFile -Append
Write-Output " Build: $CUITBuildPath" | Out-File -FilePath $LogFile -Append
# --DEBUG ONLY--> Write-Output " Recursion: $RecurseLevel" | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
# Set TCM arguements....
$ArguementPlanID = "/planid:$PlanID"
$ArguementTitle = "/title:$Title - $Path (SuiteID: $SuiteID)"
$ArguementSuiteID = "/suiteid:$SuiteID"
$ArguementConfigurationID = "/configid:$ConfigurationID"
$ArguementTFSCollection = "/collection:$TFSCollection"
$ArguementTeamProject = "/teamproject:$TFSTeamProject"
if(![string]::IsNullOrEmpty($CUITBuildPath))
$ArguementBuildDirectory = "/builddir:$CUITBuildPath"
$ArguementBuild = ""
$ArguementBuildDefinition = ""
else
$ArguementBuildDirectory = ""
$ArguementBuild = "/build:$TFSBuild"
$ArguementBuildDefinition = "/builddefinition:$BuildDefinition"
$ArguementTestEnvironment = "/testenvironment:$WebServer"
$ArguementSettingsName = ""
if(![string]::IsNullOrEmpty($SettingsName))
$ArguementSettingsName = "/settingsname:$SettingsName"
# Create test run....
Write-Host "$TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTFSCollection $ArguementTeamProject $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName"
Write-Output " $TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTFSCollection $ArguementTeamProject $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName" | Out-File -FilePath $LogFile -Append
try
$TestRunID = & $TCMEXE 'run' '/create' $ArguementTitle $ArguementPlanID $ArguementSuiteID $ArguementConfigurationID $ArguementTeamProject $ArguementTFSCollection $ArguementBuild $ArguementBuildDefinition $ArguementBuildDirectory $ArguementTestEnvironment $ArguementSettingsName
catch
$ExitMessage = $_Exception.Message
# --DEBUG ONLY--> Write-Output "TestRunID: $TestRunID" | Out-File -FilePath $LogFile -Append
if ($TestRunID -match '.+\:\s(?<TestRunID>\d+)\.')
# The test run ID is identified as a property in the match collection so we can access it directly by using the group name from the regular expression (i.e. TestRunID).
$TestRunID = $matches.TestRunID
$ArguementID = "/id:$TestRunID"
$TestRunResultsFile = $TempDirectory + "\TestRunResults$TestRunID.trx"
$ArguementQueryText = "/querytext:SELECT * FROM TestRun WHERE TestRunID=$TestRunID"
$ArguementResultsFile = "/resultsfile:""$TestRunResultsFile"""
Write-Host " Waiting for test run to complete ..."
Write-Host $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText
Write-Output " $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText" | Out-File -FilePath $LogFile -Append
$WaitingForTestRunCompletion = $true
$WaitCount= 0
while ($WaitingForTestRunCompletion)
$WaitCount = $WaitCount + 1
Write-Output " Waiting ($WaitCount)...." | Out-File -FilePath $LogFile -Append
Start-Sleep -s $TestRunWaitDelay
$TestRunStatus = & $TCMEXE 'run' '/list' $ArguementTeamProject $ArguementTFSCollection $ArguementQueryText
$TestRunStatus
if ($TestRunStatus.Count -lt 3 -or ($TestRunStatus.Count -gt 2 -and $TestRunStatus.GetValue(2) -match '.+(?<DateCompleted>\d+[/]\d+[/]\d+)'))
$WaitingForTestRunCompletion = $false
Write-Host "Evaluating test run $TestRunID results..."
# Take small pause(s) since the results might not be published yet....
Start-Sleep -s $TestRunWaitDelay
# Export results....
Write-Host $TCMEXE 'run' '/export' $ArguementID $ArguementTeamProject $ArguementTFSCollection $ArguementResultsFile
Write-Output " $TCMEXE 'run' '/export' $ArguementID $ArguementTeamProject $ArguementTFSCollection $ArguementResultsFile" | Out-File -FilePath $LogFile -Append
$WaitingForTestRunExport = $true
$WaitCount= 0
while ($WaitingForTestRunExport -and $WaitCount -lt 5)
$WaitCount = $WaitCount + 1
Write-Output " Waiting ($WaitCount)...." | Out-File -FilePath $LogFile -Append
$ExportResult = & $TCMEXE 'run' '/export' $ArguementID $ArguementResultsFile $ArguementTFSCollection $ArguementTeamProject
if ([System.IO.File]::Exists($TestRunResultsFile))
$WaitingForTestRunExport = $false
if ([System.IO.File]::Exists($TestRunResultsFile))
# Load the XML document contents.
[xml]$TestResultsXML = Get-Content "$TestRunResultsFile"
# Extract the results of the test run.
$TotalTests = $TestResultsXML.TestRun.ResultSummary.Counters.total
$PassedTests = $TestResultsXML.TestRun.ResultSummary.Counters.passed
$FailedTests = $TestResultsXML.TestRun.ResultSummary.Counters.failed
$InconclusiveTests = $TestResultsXML.TestRun.ResultSummary.Counters.inconclusive
# Output the results of the test run.
Write-Host "========== Test: $TotalTests tests ran, $PassedTests succeeded, $FailedTests failed, $InconclusiveTests inconclusive =========="
Write-Output "--------------------------------------------------------------------------------" | Out-File -FilePath $LogFile -Append
Write-Output "Summary:" | Out-File -FilePath $LogFile -Append
Write-Output "--------------------------------------------------------------------------------" | Out-File -FilePath $LogFile -Append
Write-Output " Total: $TotalTests" | Out-File -FilePath $LogFile -Append
Write-Output " Passed: $PassedTests" | Out-File -FilePath $LogFile -Append
Write-Output " Failed: $FailedTests" | Out-File -FilePath $LogFile -Append
Write-Output " Inconclusive: $InconclusiveTests" | Out-File -FilePath $LogFile -Append
$SumFailed += $FailedTests
$SumInconclusive += $InconclusiveTests
# Remove the test run results file.
[System.IO.File]::Delete($TestRunResultsFile) | Out-Null
# Add "current" TestRunID to the list of TestRunID(s)....
if ($ListTestRunID -ne $null)
$ListTestRunID = $ListTestRunID + ', '
$ListTestRunID = $ListTestRunID + $TestRunID
# Next test suite....
4. Extract record set of test runs  from TFS via SQL query:
# FUNCTION: Retrieve-TestRuns
# Parameters:
# (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
# (2.) Connection -- Database connection
# (3.) ListTestRunID -- List of test run identifiers
Function Retrieve-TestRuns
param
[Parameter(Mandatory=$True)][String]$LogFile,
[Parameter(Mandatory=$True)]$Connection,
[Parameter(Mandatory=$True)][String]$ListTestRunID
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output "Retrieve test run(s): " | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
$TestRuns = '(' + $ListTestRunID + ')'
$Command = New-Object System.Data.SqlClient.SqlCommand
$SQLStatement = "
WITH
cte_State
AS
SELECT 0 AS [StateID], 'Unspecified' AS [StateName]
UNION ALL
SELECT 1 AS [OutcomeId], 'To Be Determined (1)' AS [StateName]
UNION ALL
SELECT 2 AS [StateID], 'In Progress' AS [StateName]
UNION ALL
SELECT 3 AS [StateID], 'Completed' AS [StateName]
UNION ALL
SELECT 4 AS [StateID], 'Aborted' AS [StateName]
UNION ALL
SELECT 5 AS [OutcomeId], 'To Be Determined (5)' AS [StateName]
UNION ALL
SELECT 6 AS [StateID], 'Needs Investigation' AS [StateName]
SELECT
TR.[ProjectId] AS [Project Id],
P.[ProjectName],
TR.[TestPlanId] AS [Plan Id],
TP.Name AS [TestPlanName],
TR.[TestRunId] AS [Run Id],
TR.[Title],
S.[StateID] AS [State Id],
S.[StateName] AS [State],
TR.[StartDate] AS [Date Started],
TR.[CompleteDate] AS [Date Completed],
DATEDIFF(SECOND, TR.[StartDate], TR.[CompleteDate]) AS Duration,
TR.[Type],
TR.[IsAutomated],
TR.[TotalTests] AS [Total],
TR.[PassedTests] AS [Passed],
TR.[IncompleteTests] AS [Incomplete],
TR.[UnanalyzedTests] AS [Unanalyzed],
TR.[NotApplicableTests] AS [Not Applicable]
FROM
[Tfs_DefaultCollection].[dbo].[tbl_TestRun] AS TR
INNER JOIN [Tfs_DefaultCollection].[dbo].[tbl_Project] AS P ON TR.ProjectId = P.ProjectId
INNER JOIN [Tfs_DefaultCollection].[dbo].[tbl_Plan] AS TP ON TR.TestPlanId = TP.PlanId
INNER JOIN cte_State AS S ON TR.[State] = S.[StateID]
WHERE
TR.TestRunId IN $($TestRuns)
ORDER BY
TR.[StartDate]
$Command.CommandText = $SQLStatement
$Command.Connection = $Connection
$Command.CommandTimeout = 30
$DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$DataAdapter.SelectCommand = $Command
$DataSet = New-Object System.Data.DataSet
$DataAdapter.Fill($DataSet) | Out-Null
Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
# --DEBUG ONLY--> $DataSet.Tables[0]
return $DataSet
5. Extract record set of test results from TFS via SQL query:
# FUNCTION: Retrieve-TestRunResults
# Parameters:
# (1.) LogFile -- Name of log file (e.g., C:\Temp or C:\Temp\DEPLOY_DatabaseServer_WebCMS2_DF06_20131031.6.log)
# (2.) Connection -- Database connection
# (3.) ListTestRunID -- List of test run identifiers
Function Retrieve-TestRunResults
param
[Parameter(Mandatory=$True)][String]$LogFile,
[Parameter(Mandatory=$True)]$Connection,
[Parameter(Mandatory=$True)][String]$ListTestRunID
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output "Retrieve test result(s): " | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
$TestRuns = '(' + $ListTestRunID + ')'
$Command = New-Object System.Data.SqlClient.SqlCommand
$SQLStatement = "
WITH
cte_Outcome
AS
SELECT 0 AS [OutcomeId], 'To Be Determined (0)' AS [OutcomeName]
UNION ALL
SELECT 1 AS [OutcomeId], 'In Progress' AS [OutcomeName]
UNION ALL
SELECT 2 AS [OutcomeId], 'Passed' AS [OutcomeName]
UNION ALL
SELECT 3 AS [OutcomeId], 'Failed' AS [OutcomeName]
UNION ALL
SELECT 4 AS [OutcomeId], 'Inconclusive' AS [OutcomeName]
UNION ALL
SELECT 5 AS [OutcomeId], 'To Be Determined (5)' AS [OutcomeName]
UNION ALL
SELECT 6 AS [OutcomeId], 'Aborted' AS [OutcomeName]
UNION ALL
SELECT 7 AS [OutcomeId], 'Blocked' AS [OutcomeName]
UNION ALL
SELECT 8 AS [OutcomeId], 'Not Executed' AS [OutcomeName]
UNION ALL
SELECT 10 AS [OutcomeId], 'Error' AS [OutcomeName]
UNION ALL
SELECT 11 AS [OutcomeId], 'Not Applicable' AS [OutcomeName]
UNION ALL
SELECT 12 AS [OutcomeId], 'Paused' AS [OutcomeName]
UNION ALL
SELECT 13 AS [OutcomeId], 'To Be Determined (13)' AS [OutcomeName]
UNION ALL
SELECT 255 AS [OutcomeId], 'Never Run' AS [OutcomeName]
cte_State
AS
SELECT 0 AS [StateID], 'None' AS [StateName]
UNION ALL
SELECT 1 AS [StateID], 'Ready' AS [StateName]
UNION ALL
SELECT 2 AS [StateID], 'Completed' AS [StateName]
UNION ALL
SELECT 3 AS [StateID], 'Not Ready' AS [StateName]
UNION ALL
SELECT 4 AS [StateID], 'In Progress' AS [StateName]
UNION ALL
SELECT 5 AS [StateID], 'To Be Determined' AS [StateName]
SELECT DISTINCT
TR.[TestRunId] AS [Run Id],
TR.[TestCaseId] AS [Case Id],
O.[OutcomeID] AS [Outcome Id],
O.[OutcomeName] AS [Outcome],
S.[StateID] AS [State Id],
S.[StateName] AS [State],
TR.[TestCaseTitle] AS [Title],
TR.[AutomatedTestName] AS [Automation Method],
TR.[DateStarted] AS [Date Started],
TR.[DateCompleted] AS [Date Completed],
DATEDIFF(SECOND, TR.[DateStarted], TR.[DateCompleted]) AS Duration,
TR.[FailureType] AS [Failure Type],
TR.[ErrorMessage] AS [Error]
FROM
[Tfs_DefaultCollection].[dbo].[tbl_TestResult] AS TR
INNER JOIN cte_Outcome AS O ON TR.Outcome = O.OutcomeID
INNER JOIN cte_State AS S ON TR.State = S.StateID
WHERE
TR.TestRunId IN $($TestRuns)
ORDER BY
TR.[TestRunId],
O.[OutcomeName],
TR.[TestCaseTitle]
$Command.CommandText = $SQLStatement
$Command.Connection = $Connection
$Command.CommandTimeout = 30
$DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$DataAdapter.SelectCommand = $Command
$DataSet = New-Object System.Data.DataSet
$DataAdapter.Fill($DataSet) | Out-Null
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output "SQL Statement: " | Out-File -FilePath $LogFile -Append
Write-Output '--------------------------------------------------------------------------------' | Out-File -FilePath $LogFile -Append
Write-Output "$SQLStatement" | Out-File -FilePath $LogFile -Append
# --DEBUG ONLY--> $DataSet.Tables[0]
return $DataSet
6. Email results to distribution list  
    Currently, I'm simplifying the extraction of suite path ... replacing hardcoded depth with STUFF() & XML PATH
Carl.

Similar Messages

  • How to find all tables that are associated with a given domain name.

    I want to find all table, excluding the structures, of a given domain name, say, waers.
    Some of the tables are directly contains the domains while others are related with a data element which is connected to that domain.
    I want to find tables for all two case -either tables connected directly to the domain or connected via data element- and exclude the structures.
    thanks in advance.

    Hi,
    The following thing may help you.
    in se11-> search for tables having names like 'DD*'.
    From this list of tables you can find the required table to get domain, data element nad table name.
    one way of doing it:
    SELECT rollname domname
      FROM dd04l
      INTO CORRESPONDING FIELDS OF TABLE it_tab.
    SELECT rollname tabname
      FROM dd03l
      INTO CORRESPONDING FIELDS OF TABLE it_tab1
      FOR ALL ENTRIES IN it_tab
      WHERE rollname = it_tab-rollname.
    SORT it_tab1.
    DELETE ADJACENT DUPLICATES FROM it_tab1.
    LOOP AT it_tab1 INTO wa_tab.
      MODIFY it_tab FROM wa_tab
      TRANSPORTING tabname
      WHERE rollname = wa_tab-rollname.
    ENDLOOP.
    LOOP AT it_tab INTO wa_tab.
      WRITE:/ wa_tab-domname,
              wa_tab-tabname.
    ENDLOOP.
    Regards,
    Manoj Kumar P

  • Sql query to find all contacts for an account

    I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
    I am also looking for sql query to find all ship to addresses for an account number.
    Thanks.

    Can you also post the query for people who read this post and are also looking for an answer?
    Regards,
    Johan Louwers.

  • BO SDK Query to find all folders that a user has access to

    Hi Experts
    Please help me on BO SDK Query to "find all folders that a user has access in a single query".
    I am tried trial & error using PARENTS & CHILDREN. nothing worked
    Please advice
    Thanks!
    Prasath

    Hi Aasavari
    I am checking BO Web services samples and .NET samples. Please advice me the correct files to check the user/folder rights.
    Thank you so much
    Prasath
    http://wiki.sdn.sap.com/wiki/display/BOBJ/NETWebServicesSDKSamples

  • Where should I store the collatoral files that are associated with photos stored in lightroom?

    Where should I store the collatoral files that are associated with photos stored in lightroom? Items such as pdf files, word documents, etc. How should I connect them to each other so I can find both the photo and the related data?

    Lightroom itself will not help you with pdf, word, etc.
    However, there is a plugin you can use called AnyFile which will allow you to manage these documents in Lightroom (by assigning keywords and other metadata) so that you can search for all documents (photos, pdf, word, music, powerpoint, etc.) with given metadata.
    Because you do this via metadata, it doesn't matter where you put these files. Put them anywhere you want.

  • Query to show all A/P invoices associated with a PO

    Hi,
    I need some help to create a query to show all A/P invoices associated with a PO. I would like the input to be a PO# and the output to show all the A/P invoices and be able to drill down to the A/P invoices.
    Any help would be appreciated.
    Thanks!
    Jane

    hi,
    P.O target documents query try this,
    SELECT distinct 'GRN', D0.DocNum,D0.DocDate, D0.DocDueDate, D0.DocTotal,'AP INV', I0.DocNum,I0.DocDate, I0.DocDueDate, I0.DocTotal, I0.PaidToDate
    FROM ((OPDN D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry) full outer join (OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry) on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
    WHERE (D1.BaseType=22 AND D1.BaseRef='[%0]') OR (I1.BaseType=22 AND I1.BaseRef='[%0]') OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry FROM PDN1 WHERE BaseType=22 AND BaseRef='[%0]'))
    Jeyakanthan

  • SQL query to find all responsibilities containing a given submenu?

    Ok, I've searched all over this place and I can't quite get what I want. I can get all responsibilities with a given function, and I can get all responsibilities with a given menu, but I can't get all responsibilities with a given SUBmenu. Specifically, I'm trying to get all responsibilities that have "Desktop Integration Menu" somewhere in their menu tree, whether it be menu or submenu. All I can do is get the ones where it's the menu (i.e. the seeded Desktop Integration responsibilities). Can anyone give me some assistance with this query? It's driving me nuts. Below is the SQL query as it stands now. Thanks!
    SELECT DISTINCT frt.responsibility_name, fmt.user_menu_name, fr.menu_id,fme.sub_menu_id
    FROM apps.fnd_responsibility_tl frt,
    apps.fnd_responsibility fr,
    apps.fnd_menus_tl fmt,
    apps.fnd_menus fm,
    apps.fnd_menu_entries fme
    WHERE frt.responsibility_id(+) = fr.responsibility_id
    AND fr.menu_id = fmt.menu_id
    AND fr.menu_id = fm.menu_id
    AND fme.sub_menu_id = fr.menu_id
    AND frt.LANGUAGE = 'US'
    AND fr.end_date IS NULL
    AND sub_menu_id = '1004193'
    ORDER BY frt.responsibility_name ASC

    Please see these docs.
    How To get List Of Functions Which Are Setup For A Responsibility? [ID 549100.1]
    How to identify all Menus / Responsibilities Associated with a Given Function [ID 238653.1]
    Script To Extract Submenu And Function Information About A Menu [ID 458701.1]
    HOW TO GENERATE MENU TREE FOR A MENU ATTACHED TO A RESPONSIBILITY IN ORACLE APPLICATIONS 11i ? [ID 312014.1]
    Thanks,
    Hussein

  • Query Builder - Find WEBI reports that are using a table

    I am trying to find list of WEBI reports using a specific table. This specific table is used in only 1 universe.
    Though I could successfully find list of reports that use this universe, I am unable to find drill down further and find the subset of reports using this table/object.
    SELECT si_name, SI_KIND, si_id, SI_PARENTID,SI_AUTHOR,SI_OWNER FROM CI_INFOOBJECTS, CI_APPOBJECTS
    WHERE PARENTS("SI_NAME='WEBI-UNIVERSE'","SI_NAME ='MyUniverse'")
    Is it possible to find the information I am looking for using query builder.
    Also, for a given WEBI report I am trying to find the list of report names and the folder they reside in:
    Select SI_NAME, SI_ID, SI_PATH, SI_KIND, SI_OWNER From CI_INFOOBJECTS, CI_APPOBJECTS WHERE
    PARENTS("SI_NAME='Folder Hierarchy'",
    "PARENTS('SI_NAME=''WEBI-UNIVERSE'' ', 'SI_NAME=''MyUniverse'' ')" )
    The above query just gives me the folder names. I am looking to find the report names as well the the folder (and preferably the path) in a single query. Is that possible.

    Sri,
    With respect to your 1st requirement:
    In BusinessObjects 6.5 it was possible. However, post BOXIR2 this information could not be retrieved from CMS via query builder.  I agree with Jorge Sosua's comment above.
    With respect to your 2nd requirement:
    The field 'SI_PATH' will retrieve Filestore path(physical path). If you were referring logical path(Public folder path or psuedo-reference path) will you please refer my respone to Kelly Stone at BusinessObjects Query builder queries - Part II , If this may assist you.
    Regards,
    Sandeep

  • SQL query to find Approved projects which are open

    Hi,
    Can anyone provide a SQL query which will show only the approved projects which are open.
    Thanks
    Titas

    Try this
    select PROJECT_ID , NAME from pa_projects_all
    where project_status_code = 'APPROVED'
    and NVL(CLOSED_DATE,SYSDATE+1) > SYSDATE
    Thanks
    Pradeep

  • How to find all routes that are going out an interface in IOS-XR.

    Hi all,
    So if I have the following set up in IOS:
    interface GigabitEthernet7/0/0.265
    encapsulation dot1Q 265
    ip vrf forwarding test
    ip address 1.1.1.1 255.255.255.252
    ip verify unicast reverse-path
    end
    ip route vrf Apollo 2.2.2.0 255.255.255.248 1.1.1.2
    I can see all the routes that are going out the interface using show ip cef command:
    ios-router#show ip cef vrf test GigabitEthernet7/0/0.265
    2.2.2.0/29
      nexthop 1.1.1.2 GigabitEthernet7/0/0.265
    1.1.1.0/30
      attached to GigabitEthernet7/0/0.265
    1.1.1.2/32
      attached to GigabitEthernet7/0/0.265
    In case of IOS-XR (ASR9K 4.3.2 or 4.3.1) the same setup and command shows only
    attached routes:
    router static
    vrf test
      address-family ipv4 unicast
       2.2.2.0/29 1.1.1.2
    RP/0/RSP0/CPU0:TST_riga-sb7-pe-asr9#show cef vrf test bundle-ether2.265
    Prefix              Next Hop            Interface
    1.1.1.0/30          attached            Bundle-Ether2.2220333
    1.1.1.0/32          broadcast           Bundle-Ether2.2220333
    1.1.1.1/32          receive             Bundle-Ether2.2220333
    1.1.1.2/32          1.1.1.2             Bundle-Ether2.2220333
    1.1.1.3/32          broadcast           Bundle-Ether2.2220333
    Is there any command to see all the routes that are going out an interface without complicated parsing
    of the configuration, recursive show cef commands etc.?

    You can accomplish this with the "show route" command.  Here is an example:
    P/0/RSP1/CPU0:ASR9006-E#sh route next-hop tenGigE 0/3/0/2
    Tue Oct  8 15:34:58.046 UTC
    Codes: C - connected, S - static, R - RIP, B - BGP
           D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
           N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
           E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
           i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
           ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
           U - per-user static route, o - ODR, L - local, G  - DAGR
           A - access/subscriber, - FRR Backup path
    Gateway of last resort is 172.18.87.1 to network 0.0.0.0
    D    10.95.248.1/32 [90/128512] via 10.129.56.210, 4d00h, TenGigE0/3/0/2
    C    10.129.56.208/30 is directly connected, 4d00h, TenGigE0/3/0/2
    L    10.129.56.209/32 is directly connected, 4d00h, TenGigE0/3/0/2
    O    10.242.142.240/30 [110/20] via 10.129.56.210, 3d11h, TenGigE0/3/0/2
                           [110/20] via 10.129.56.214, 3d11h, TenGigE0/3/0/3
    D    192.168.1.16/32 [90/128512] via 10.129.56.210, 4d00h, TenGigE0/3/0/2
    D    192.168.20.39/32 [90/128512] via 10.129.56.210, 4d00h, TenGigE0/3/0/2
    RP/0/RSP1/CPU0:ASR9006-E#
    Thanks,
    Bryan

  • SQL Query, to know the list of Invoices associated with a sales order

    Hello All,
    Can any one let me know the query to know the list of all the invoices associated with a sales order.
    Please do the needful.
    Thanks,

    Hello All,
    Please let me know is this possible to have the list of Invoices for an associated Sales Order.
    Thanks,
    Abdul

  • Why won't Index tags that are associated with more than one topic work on a Mac?

    I used RoboHelp 8 to generate a project for PCs and Macs. An index entry ("documentation", in the following examples) is associated with two topics. If I click that index entry in the output on a PC, the appropriate topic links appear and I can jump to the topics. On a Mac, any index entry that has more than one topic associated with it will not work. I just wondering if anyone else has experienced this.

    I suspect but cannot confirm it is a browser issue with output from an older version of Rh. Can you install the Rh10 trial on a machine other than your normal production machine?
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • SQL query to find all the custom folders in Discoverer (query posted)

    I know its not a question I am posting..this is just to inform community users that this query makes life easier in case someone wants to find out all the custom folders in a particular EUL (folder name starting with XX)
    select b.ba_name,f.obj_name folder_name,f.obj_id,f.obj_ext_owner Owner
    from
    APPS.EUL5_objs f
    , APPS.EUL5_ba_obj_links l
    , APPS.EUL5_bas b
    where 1=1
    and f.obj_id= l.bol_obj_id
    and b.ba_id= l.bol_ba_id
    and b.ba_name like 'XX%'
    order by b.ba_name,f.obj_name;
    Hopefully it would be useful to others!

    Connect as sysdba and try..
    To list all objects >100M in size.
    SQL> select owner, segment_type, segment_name, sum(bytes)/(1024*1021) from dba_segments
    group by owner, segment_type, segment_name
    having sum(bytes)/(1024*1021) > 100
    For tablespaces ..
    select tablespace_name, sum(bytes) tablespace_size
    from dba_data_files
    group by tablespace_name
    union all
    select tablespace_name, sum(bytes) tablespace_size
    from dba_temp_files
    group by tablespace_name
    order by tablespace_name

  • Query to find all Partynames that come under the Global party Name

    Hi All
    I need a query to which can help me in listing all the Partynames that come under the top most rolled up customer
    I need output like this:
    PartyName,Party_number,Global_PartyName,GlobalRegistryId
    Please help me.
    Thanks
    Bhavana

    Could you please help me.. I am new to EBS..
    Thanks
    Bhavana
    Edited by: user13689917 on Jan 17, 2011 3:49 PM

  • Stuck on sql query to find parent records that have the same child records

    Oracle 10gR2 Enterprise Edition.
    Hi,
    I'm trying to write some logic to look for records in a parent table, which have the exact same values in a child table.
    This is part of a bigger query, but I'm stuck on this part for now, so I've mocked up some simplified tables below to capture the core of the
    problem I'm stuck on.
    Let say I've got a parent table Manager, a child table Employee and there's a many to many relationship between them.
    The aptly named Join_Table handles the relationship between them. So one manager can manage many employees, one employee can be managed by
    many managers.
    I've a feeling this is stupidly easy, but I seem to be suffering from a bad bout of brain freeze today!
    -- parent table
    CREATE TABLE manager (
    id      number primary key,
    name      varchar2(100));
    -- child table
    CREATE TABLE employee (
    id          number primary key,
    name      varchar2(100));
    -- link table
    CREATE TABLE join_table (
    manager_id          NUMBER,
    employee_id      NUMBER,
    CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id),
    CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id),
    CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id)
    -- Insert some managers
    INSERT INTO manager (id, name) VALUES (1, 'John');
    INSERT INTO manager (id, name) VALUES (2, 'Bob');
    INSERT INTO manager (id, name) VALUES (3, 'Mary');
    INSERT INTO manager (id, name) VALUES (4, 'Sue');
    INSERT INTO manager (id, name) VALUES (5, 'Alan');
    INSERT INTO manager (id, name) VALUES (6, 'Mike');
    -- Insert some employees
    INSERT INTO employee (id, name) VALUES (101, 'Paul');
    INSERT INTO employee (id, name) VALUES (102, 'Simon');
    INSERT INTO employee (id, name) VALUES (103, 'Ken');
    INSERT INTO employee (id, name) VALUES (104, 'Kevin');
    INSERT INTO employee (id, name) VALUES (105, 'Jack');
    INSERT INTO employee (id, name) VALUES (106, 'Jennifer');
    INSERT INTO employee (id, name) VALUES (107, 'Tim');
    -- Insert the links
    -- John manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103);
    -- Bob manages Paul, Simon, Kevin, Jack
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105);
    -- Mary manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107);
    -- Sue manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107);
    -- Alan manages Paul, Simon, Ken, Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107);
    -- Mike manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103);
    -- For sanity
    CREATE UNIQUE INDEX employee_name_uidx ON employee(name);So if I'm querying for manager John, I want to find the other managers who manage the exact same list of employees.
    Answer should be Mike.
    If I'm querying for manager Mary, answer should be Sue.
    This query will give me the list of managers who manage some of the same employees as John, but not the exact same employees...
    SELECT DISTINCT m.name AS manager
    FROM manager m, join_table jt, employee e
    WHERE m.id = jt.manager_id
    AND jt.employee_id = e.id
    AND e.id IN (
         SELECT e.id
         FROM manager m, join_table jt, employee e
         WHERE m.id = jt.manager_id
         AND jt.employee_id = e.id
         AND m.name = 'John')
    ORDER BY 1;I thought about using set operations to find managers whose list of employees minus my employees is null and where my employees minus their list of employees is null. But surely there's a simpler more elegant way.
    Any ideas?
    Btw, I need to run this as a batch job against tables with >20 million rows so query efficiency is key.

    What about...
    WITH manager_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id
      AND   m.name = :P_MANAGER)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    ), all_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    SELECT a.*
    FROM   manager_list m,
           all_list a
    WHERE  m.employees = a.employeesWould be easier in 11g, but I don't have an installation here so this is based on 10g.
    Cheers
    Ben

Maybe you are looking for

  • Access to files on external hard drive.

    Hi, I have a really annoying problem. I have a sata hdd connected via usb to my pc. I am running windows 8.1. The external hard drive belongs to a friend that wants their data. I can locate the folders in explorer. But when I try to copy any of the f

  • "iTunesSetup.exe is not a valid 32bit application" error received.

    "iTunesSetup.exe is not a valid 32bit application" error received.  I'm on dial up (no flames or stupid comments in reference to this please) with Toast using IE9.  I've uninstalled, deleted, and restarted my computer after each attempt.  I've tried

  • Help with displaying a JTree

    Hi, I have developed a webspider that cycles through a website detecting all urls and checking for borken links. I currently have build a JTree that takes the current url that is being processed and creates a string and adds it to a JTree. The proble

  • Convert PDF to Base64

    Hello everyone, We have implemented in our SAP the Digital Invoice Mexico. We send a XML file based on the billing document according of all SAP Notes. This process was perfect. Now we have a customer that need to receive a PDF file encoding in base6

  • Placing Fields in Window

    Hi Everyone, I am new to java and I am trying to create a window where I can enter an address. I could not figure out how to place the JTextFields where I want to. This is how I want to place them. Name Address1 Address2 City, State Zip Please help??