I’m updating queries that were using the old construction for outer joins (=* and *=). I have 3 tables that I need to include in an outer join.
The original query is:
SELECT s.SkillID ,
NULL AS Signature ,
NULL AS DPL ,
CASE WHEN ISNULL(ds.DPL, dg.DPL) IS NULL
THEN p.ScaleTo - p.ScaleFrom + 1
ELSE ISNULL(ds.DPL, dg.DPL)
END AS DefaultDPL
FROM tbJobs j ,
tbSkills s
INNER JOIN tbSkillGroups sg ON s.SkillGroupID = sg.SkillGroupID ,
tbPerfScales p ,
tbDPLs ds ,
tbDPLs dg
WHERE j.JobID = 866
AND ( ds.LevelID=*j.LevelID
AND ds.IDType = 1
AND ds.GroupOrSkillID=*s.SkillID
)
AND ( dg.LevelID=*j.LevelID
AND dg.IDType = 0
AND dg.GroupOrSkillID=*sg.SkillGroupID
)
AND ( ( s.PerfScaleID IS NOT NULL
AND p.PerfScaleID = s.PerfScaleID
)
OR ( s.PerfScaleID IS NULL
AND p.PerfScaleID = sg.PerfScaleID
)
)
I’m doing:
SELECT s.SkillID ,
NULL AS Signature ,
NULL AS DPL ,
CASE WHEN ISNULL(ds.DPL, dg.DPL) IS NULL
THEN p.ScaleTo - p.ScaleFrom + 1
ELSE ISNULL(ds.DPL, dg.DPL)
END AS DefaultDPL
FROM tbPerfScales p ,
tbSkills s
INNER JOIN tbSkillGroups sg ON s.SkillGroupID = sg.SkillGroupID ,
tbJobs j
LEFT OUTER JOIN tbDPLs ds ON j.LevelID = ds.LevelID
AND s.SkillID = ds.GroupOrSkillID
LEFT OUTER JOIN tbDPLs dg ON j.LevelID = dg.LevelID
AND sg.SkillGroupID = dg.GroupOrSkillID
WHERE j.JobID = 866
AND ds.IDType = 1
AND dg.IDType = 0
AND ( ( s.PerfScaleID IS NOT NULL
AND p.PerfScaleID = s.PerfScaleID
)
OR ( s.PerfScaleID IS NULL
AND p.PerfScaleID = sg.PerfScaleID
)
)
For some reason I’m getting the error:
The multi-part identifier “s.SkillID” could not be bound.
And I know is in this part:
tbJobs j
LEFT OUTER JOIN tbDPLs ds ON j.LevelID = ds.LevelID
AND s.SkillID = ds.GroupOrSkillID
I’m not sure what I’m doing wrong.
Thanks any help.
Jose
There is a comma after the statement
Which is because you have tbJobs after it, when it should be in the other tables. I would recommend using CROSS JOIN instead of just having multiple tables in the FROM clause as it will be more clear.
Here is the base rewrite of your query that should work, though you should be able to easily get rid of most of the cross joins.