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

Similar Messages

  • Query for retreiving table names that have the same data

    Hi,
    Does anybody know how to retreive all the table names that have the same data in their respective tables but i dont know the table names or its fields. Is there any possible query to perform this action???
    Thanks in Advance,
    Balaji.

    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

  • Query to find no of peoples with the same age(using distinct)

    query to find no of peoples with the same age(using distinct)
    Edited by: swordfish3 on Mar 7, 2009 9:24 PM

    it would be helpful if you posted some proper sample data with proper expected results.
    The easier you make it for us to help you, the more likely you will get helped.

  • 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.

  • Query to find parent & al children customer based on child Party_number

    Hi All,
    I am working analyzing some TCA hierarchy data for a new customer dimension table design for a project and also for better understanding of the TCA.
    I need a query which can help me in listing all the PARTY IDs of all the customers that come under the top most rolled up customer which is found based on an any random input CHILD PARTY NUMBER.
    In simple terms.
    1. I have any random PARTY NUMBER of any customer in HZ PARTY.
    2. Using that PARTY NUMBER I need to find it's top most level rolled up parent customer.(i.e. Which global parent customer it falls under)
    3. Now based on the global customer found in the second step, I need to find all the customers (and all its global subsidiaries) under that one global name.(All the customers which are spread across the glob)
    I am currently using the following tables to build the logic.
    hz_parties
    hz_relationships
    hz_hierarchy_nodes
    fnd_lookup_values
    Anybody who has done such an exercise or has any kind of inputs, queries which can help, etc.. it would be really helpful.
    Thanks a lot.
    Thank you,
    Warm Regards
    Goldi

    hi goldie,
    u can use
    party_id (pk) from hz_parties,
    party_id(fk) and cust_account_id(pk) from hz_cust_accounts,
    cust_account_id(fk) from AR.HZ_CUST_ACCT_RELATE_ALL.
    i hope u can get the way for your answer..
    pls let me know, it worked or not.
    Regards.
    Pushpal

  • Write the sql query to find largest value in row wise without using   great

    write the sql query to find largest value in row wise without using
    greatest fuction?

    Another not so good way, considering you want greatest of 4 fields from a single record:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
      2  union select 500,600,700,800 from dual
      3  union select 900,1000,1100,1200 from dual
      4  union select 1300,1400,1500,1600 from dual
      5  union select 1700,1800,1900,2000 from dual
      6  union select 2100,2200,2300,2400 from dual
      7  union select 2800,2700,2600,2500 from dual
      8  union select 2900,3000,3100,3200 from dual)
      9  SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
    10  FROM
    11  (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
    12         (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
    13         (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
    14  FROM
    15  (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
    16         (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
    17         (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
    18         (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
    19* FROM t))
    SQL> /
    MAX_VALUE
           400
           800
          1200
          1600
          2000
          2400
          2800
          3200
    8 rows selected.
    SQL> Edited by: AP on Sep 21, 2010 6:29 AM

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • SQL Query to find menus and submenus attached to responsibility

    Hi,
    I am looking for help to find out a sql query to pull out the list of all the menu's associated with each of the responsibilities assigned to users. Please let me know any SQL query to find out menus attached for responsibilities assigned to users.

    835129 wrote:
    I was asked by my lead to list out responsibilities and attached menus and I was asked to submit the output from production. In the metalink note provided by you it was asked to create table collecting all menu id's and I cannot create any tables in production. Apart from this there were 1000's of users with different responsibilities and different menus. I cannot collect all of the users menu ids.
    I just want to list out responsibilities and attached menus. Is that something you can helpout withhttps://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_vl+AND+fnd_menu&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_tl+AND+FND_MENU_ENTRIES_TL&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Please search the forum for these tables/views and you should get many hits:
    FND_MENU_ENTRIES_TL
    FND_MENU_ENTRIES_VL
    FND_RESPONSIBILITY_TL
    FND_RESPONSIBILITY_VL
    Thanks,
    Hussein

  • 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.

  • SQl query to find incompatibility defined

    If two programs are defined as incompatible with one another, the data these programs cannot access simultaneously must also be identified.
    This can be found from concurrent program->define from front end ebs login, but is there any SQL query to find this for a particular program or request set??
    Thanks in advance.

    Please search the forum before posting similar questions.
    Concurrent-Conflict
    Re: Concurrent-Conflict
    Thanks,
    Hussein

  • SQL Query to find DN and phone Load

    Hi All,
    We are using Call Manager 8.6 [one PUB and 4 SUBs] and have different IP phone models .
    IP phone model have different LOAD working with them like few 3905 have cmterm-3905.9-2-2-0 while some have cmterm-3905.9-2-2ES7 .
    Is there any way/SQL Query  to find out what all phone model with DN are running 3905.9-2-2.0 LOAD?
    regds,
    aman

    Hey Aman,
    Hope all is well my friend!
    Just to add a note to my friend Carlo's good info here (+5!)
    Try;
    Device> Device Settings> Firmware Load Information>Device Not Using Default Load
    This will show you any phones that deviate from the "device defaults" Fimware And if you click
    on any device listed here it will show the actual Firmware that is being used on the specified device.
    Cheers!
    Rob

  • SQL query to find sqlnet.ora parameters

    Hi All,
    I am working 11g RAC /solaris 9
    I want have sql query to find values of sqlnet.ora parameters
    May be values of SQLNET.INBOUND_CONNECT_TIMEOUT
    SQLNET.SEND_TIMEOUT, SQLNET.RECV_TIMEOUT
    Thanks
    raj

    The sqlnet.ora file is the profile configuration file. It resides on the client machines and the database server.
    Profiles are stored and implemented using this file. The database server can be configured with access control parameters in the sqlnet.ora file.
    These parameters specify whether clients are allowed or denied access based on the protocol.
    The sqlnet.ora file enables you to do the following:
    Specify the client domain to append to unqualified names
    Prioritize naming methods
    Enable logging and tracing features
    Route connections through specific processes
    Configure parameters for external naming
    Configure Oracle Advanced Security
    Use protocol-specific parameters to restrict access to the database
    By default, the sqlnet.ora file is located in the ORACLE_HOME/network/admin directory. The sqlnet.ora file can also be stored in the directory specified by the TNS_ADMIN environment variable.
    You can not query on this file sqlnet.ora as tnsnames.ora file.
    Regards
    Mahir M. Quluzade

  • SQL Query to Find out User has what all resources provisioned !

    Hi Guys ,
    Does any one have a SQL query to find out what resources are provisioned to a particular user ?
    Thanks
    Suren

    Hi,
    Hope this will help you.
    SELECT distinct usr_login as "IdM User ID",
    usr_employeeID as "Employee ID",
    usr.USR_FIRST_NAME as "First Name",
    usr.USR_LAST_NAME as "Last Name",
    usr_status
    as "User Status",
    USR_EMP_TYPE as "Employee Type",
    obj.obj_name as "Application Resource",
    ost_status as "Application Resource Status",
    FROM ost,oiu,obj,usr,obi
    WHERE oiu.ost_key = ost.ost_key AND obj.obj_key = obi.obj_key AND oiu.usr_key = usr.usr_key
    AND ost_status in ('Provisioned','Revoked','Disabled', 'Provisioning')
    AND oiu.obi_key=obi.obi_key
    AND usr_EmployeeID like '11111'
    This query will provide all the resources to which the user is linked with and the resource status is in 'Provisioned','Revoked','Disabled', 'Provisioning' status for a particular employeed ID, I am not completely sure whether I have given the Employee ID column from USR table as correct or not. Verify once and query the DB

  • SQL query to find access database files?

    Odd request, but does anyone have a SQL query to find files? Specifically, I am looking for machines that have access databases on them. .mdb & .accdb

    Have you enabled inventory for them?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ
    i was trying to figure out where that option was but couldn't find it under hierarchy settings. perhaps it's been changed since 2012 R2? can you help point it out?

Maybe you are looking for

  • Mac Mail downloads all my old messages with IMAP

    Hi, How do I stop this happening? I just want to download messages from now onwards. But I'm getting thousands of old emails downloading to my inbox and no way to stop it seemingly. I'm on Mac OSX 10.6.8, using Mail 4.6. I have an @hotmail.com email

  • My Iphone 4s is locked

    Hi Good Morning........ I have Iphone 4s i used it and i updated it for 7.1 version and it is locked after updating 7.1... What should i do now?

  • CS6 3d Rendering Won't Stop

    I applied the Extrude / Revolve to text and once it rendered the text Illustrator keeps rendering it, that is, it won't stop. There are two objects, one with a single word and the second object has 4 lines of one word on each line (peoples first/last

  • TCP/Socket Qn

    We use ServerSocket.accept() on the server-side to get a communcation "end-point" between the server and the client. The object returned is a Socket object. We typically spawn a thread to handle subsequent communication between these 2 end-points usi

  • SQL stmt fine tunning

    Hi DBA, i am new to this field. i can see from EM some sql are taking 8%- 95% of Db . i get the SQL_ID from the Em how to fine tune this? also can you please help me out with some standard recommendations to run the DB in best manner. Thanks in advan