SaltyTheFrog
Programmer
We are on SQL 2008 but our T-SQL is running at SQL 2000 compatibility level. I'm trying to convert some SQL to be compliant so we can move up the compatibility level. I'm having trouble with this one:
SQL 2000 compatibility level:
Notice the "c.fkLocation =* l.pkLocation" and "ge.fkAppStatus *= ras.pkAppStatus" joins. The result set contains 48,392 rows.
This is how I converted it:
The result set contains 48,352 rows.
The difference is 40 rows and what separates them is a column called "c.PrimaryContact" and the difference is the first query contains forty extra rows with "c.PrimaryContact" as null. From what I see "c.fkLocation =* l.pkLocation" is a right outer join and is allowing null "c.PrimaryContact" rows even though the where specifiaclly says "and isnull(c.PrimaryContact,0) = 1".
I need the null "c.PrimaryContact" rows to be in the results. Just coding for them to be allow NULL "c.PrimaryContact" rows makes the counts much greater than the forty rows. Can someone see what I am missing? I've tried a number of variations, not shown here, but I can't get the queries to match the results set of the first one.
SQL 2000 compatibility level:
Code:
select *
From
Employers e,
Contact c,
Location l,
GroupEmployer ge,
refAppStatus ras,
AssociationSubAssociation asa,
Association a
Where
c.fkLocation =* l.pkLocation
and l.fkID = e.Employerid
and l.fkType = 'e'
and isnull(l.PrimaryLocation,0) = 1
and isnull(c.PrimaryContact,0) = 1
and e.employerid = ge.fkemployer
and ge.fkAppStatus *= ras.pkAppStatus
and ge.fkAssociationSubAssociation = asa.pkAssociationSubAssociation
and asa.fkAssociation = a.pkAssociation
and asa.EstExperienceYear = '2017'
Notice the "c.fkLocation =* l.pkLocation" and "ge.fkAppStatus *= ras.pkAppStatus" joins. The result set contains 48,392 rows.
This is how I converted it:
Code:
select *
From
Employers e
join GroupEmployer ge on e.employerid = ge.fkemployer
join AssociationSubAssociation asa on ge.fkAssociationSubAssociation = asa.pkAssociationSubAssociation
join Association a on asa.fkAssociation = a.pkAssociation
join subassociation sa on sa.pksubassociation = asa.fksubassociation
join Location l on l.fkID = e.Employerid
left join Contact c on c.fkLocation = l.pkLocation
left join refAppStatus ras on ge.fkAppStatus = ras.pkAppStatus
left outer join Accountant acc on e.fkAccountant = acc.pkAccountant
Where l.fkType = 'e'
and isnull(l.PrimaryLocation,0) = 1
and isnull(c.PrimaryContact,0) = 1
and asa.EstExperienceYear = '2017'
The result set contains 48,352 rows.
The difference is 40 rows and what separates them is a column called "c.PrimaryContact" and the difference is the first query contains forty extra rows with "c.PrimaryContact" as null. From what I see "c.fkLocation =* l.pkLocation" is a right outer join and is allowing null "c.PrimaryContact" rows even though the where specifiaclly says "and isnull(c.PrimaryContact,0) = 1".
I need the null "c.PrimaryContact" rows to be in the results. Just coding for them to be allow NULL "c.PrimaryContact" rows makes the counts much greater than the forty rows. Can someone see what I am missing? I've tried a number of variations, not shown here, but I can't get the queries to match the results set of the first one.