Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:01:25+00:00 2026-05-20T16:01:25+00:00

I am trying to write a query with some fancy joins. I know this

  • 0

I am trying to write a query with some fancy joins. I know this can be done, but I am not remembering how to do it.

Here is my query as it is now:

SELECT  parentLink.SourceWorkItemID, parentLink.TargetWorkItemID,
            childLink.SourceWorkItemID, childLink.TargetWorkItemID, 
            childLink.WorkItemLinkTypeSK--,childLinkType.LinkName
FROM    dbo.FactWorkItemLinkHistory parentLink
        JOIN dbo.DimWorkItemLinkType parentLinkType (NOLOCK)
            ON parentLink.WorkItemLinkTypeSK = parentLinkType.WorkItemLinkTypeSK
        LEFT JOIN dbo.FactWorkItemLinkHistory childLink (NOLOCK)
            ON parentLink.TargetWorkItemID = childLink.SourceWorkItemID
            AND childLink.RemovedByPersonSK IS NULL
            AND childLink.WorkItemLinkTypeSK IN 
               (SELECT  sublink.WorkItemLinkTypeSK
                FROM    dbo.DimWorkItemLinkType sublink
                WHERE   sublink.LinkName = 'Child'
               )
        --LEFT JOIN dbo.DimWorkItemLinkType childLinkType (NOLOCK)
        --  ON childLink.WorkItemLinkTypeSK = childLinkType.WorkItemLinkTypeSK  
        --  AND childLinkType.LinkName = 'Child'            
WHERE   parentLink.SourceWorkItemID = 1917
        AND parentLink.RemovedByPersonSK IS NULL        
        AND parentLinkType.LinkName = 'Releases Story'

I have tried to get this to run without the select clause in the from part of my query, but it keeps eluding me.

The result I am looking for is something this:

1917    1915    1915    1916    2
1917    1913    1913    1914    2
1917    1913    1913    4349    2
1917    1921    1921    1922    2
1917    1918    NULL    NULL    NULL
1917    1920    NULL    NULL    NULL

I get that result using the select in the from clause, but I would rather not use a select there if I can avoid it.

I tried making these changes:

  1. Uncomment the last join (and childLinkType.LinkName in the main select clause)
  2. Remove the unwanted select clause (the line above the last join).

When I do I get this:

1917    1915    1915    1916    2   Child
1917    1915    1915    1917    20  NULL
1917    1915    1915    1919    7   NULL
1917    1915    1915    1911    4   NULL
1917    1913    1913    1914    2   Child
1917    1913    1913    1917    20  NULL
1917    1913    1913    1911    4   NULL
1917    1913    1913    4349    2   Child
1917    1921    1921    1922    2   Child
1917    1921    1921    1917    20  NULL
1917    1918    1918    1919    7   NULL
1917    1918    1918    1912    4   NULL
1917    1918    1918    1917    20  NULL
1917    1920    1920    1911    4   NULL
1917    1920    1920    1917    20  NULL

That is too many rows. And the I don’t want nulls matching on the DimWorkItemLinkType table. So I make the last join an inner join. Then I get this:

1917    1915    1915    1916    2   Child
1917    1913    1913    1914    2   Child
1917    1913    1913    4349    2   Child
1917    1921    1921    1922    2   Child

That has removed the items that don’t have a “child” (1918 and 1920 from the first data set). I still need them in my results.

Any ideas how I can remove the select (in the from clause) and still get this to give me the first set of results?

NOTE: I am running this against the TFS_Warehouse database on TFS 2010 server (using the tables that are approved for reporting purposes).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:01:26+00:00Added an answer on May 20, 2026 at 4:01 pm

    Well, I won’t pretend I really understand your question — as others have said, it might be worth trying to break it down and simplify it — and I don’t have a TFS_Warehouse, but I’m going to take a chance and guess that you’re looking for a structure something like this (untested, obviously):

    SELECT  parentLink.SourceWorkItemID, parentLink.TargetWorkItemID,
                childLink.SourceWorkItemID, childLink.TargetWorkItemID, 
                childLink.WorkItemLinkTypeSK--,childLinkType.LinkName
    FROM    dbo.FactWorkItemLinkHistory parentLink
            JOIN dbo.DimWorkItemLinkType parentLinkType (NOLOCK)
                ON parentLink.WorkItemLinkTypeSK = parentLinkType.WorkItemLinkTypeSK
            LEFT JOIN 
              (dbo.FactWorkItemLinkHistory childLink (NOLOCK)
                INNER JOIN dbo.DimWorkItemLinkType childLinkType (NOLOCK)
                  ON childLink.WorkItemLinkTypeSK = childLinkType.WorkItemLinkTypeSK  
                  AND childLinkType.LinkName = 'Child')
              ON parentLink.TargetWorkItemID = childLink.SourceWorkItemID
              AND childLink.RemovedByPersonSK IS NULL
    WHERE   parentLink.SourceWorkItemID = 1917
            AND parentLink.RemovedByPersonSK IS NULL        
            AND parentLinkType.LinkName = 'Releases Story'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a query for SQL Server 2005 but I can't
I am trying to write a query to find out what users are not
I'm trying to write this query, that would calculate the average value of all
I'm trying to write a LINQ query on some objects where I need to
I am trying to write a SQL query that does some complex sorting. I
I am having some trouble with a linq query I am trying to write.
I'm trying write a query to find records which don't have a matching record
I'm trying to write a query that will pull back the two most recent
I'm trying to write a query that extracts and transforms data from a table
I'm trying to write a query for an advanced search page on my document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.