Hi I have a SQL server db, when I execute following query I get 4 results:
WITH MyCTE (ID, hasLead, SubgroupFk, SubTeamFk)
AS (
SELECT [ID],[hasLead],[SubgroupFk],[SubTeamFk]
FROM [LocalGTPDatabase].[dbo].[LinkProject-Area]
where [ProjectFk]=90
)
SELECT
*
FROM MyCTE
INNER JOIN EmplTeam ON EmplTeam.ID = MyCTE.SubTeamFk
INNER JOIN [Department] ON [Department].ID = MyCTE.SubgroupFk
For every LinkProjectArea Id I have 1 Headcount item / year
Headcount table is connected with: LinkProjectAreaFk to previous mentioned table
So I thought I can combine the headcount with following query:
WITH MyCTE (ID, hasLead, SubgroupFk, SubTeamFk)
AS (
SELECT [ID],[hasLead],[SubgroupFk],[SubTeamFk]
FROM [LocalGTPDatabase].[dbo].[LinkProject-Area]
where [ProjectFk]=90
)
SELECT
*
FROM MyCTE
INNER JOIN EmplTeam ON EmplTeam.ID = MyCTE.SubTeamFk
INNER JOIN [Department] ON [Department].ID = MyCTE.SubgroupFk
INNER JOIN [HeadCount] ON [HeadCount].LinkProjectAreaFk = MyCTE.ID
But when I execute this query I get no results but every id of this query has a headcount. What am I doing wrong?
I really have no clue
If you get no error but just no data, there is probably no data.
Maybe if there is a “HeadCount”Item, there is no Department-Item or there is no Empl-Team-Item that fits.
Basically you have an and-Connection. Show all combinations of MyCTE, EmplTeam, Department and HeadCount, where ALL of your three “ON-Conditions” are valid.