Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Left Outer Join Problem

Author  Topic 

James.Hastings
Starting Member

4 Posts

Posted - 2009-01-15 : 08:14:23
I have a script that was originally used for SQL 2000. I am switching everything over to 2005, however the script contains a non-ansi left outer join syntax. I cannot seem to get the syntax to work with an ansi left outer join connection. Could someone help me with this? I marked the part with the comment "Left Outer Join."

Select 
FacilityID,
RenAct.uni_int_unitid,
RenAct.uni_vch_unitno,
RenAct.uni_int_status,
RenAct.uty_int_Id,
RenAct.futr_mny_MonthlyRent,
RenAct.tul_dtm_moveindate,
RenAct.tul_dtm_moveoutdate,
RenAct.tul_bit_transferin,
RenAct.tur_mny_NewRent,
RenAct.tul_int_Leaseno,
RenAct.uni_dtm_DateCreated,
RenAct.futr_dtm_EffectiveDate
From(
SELECT
fse_int_FacilityId as FacilityID,
stf_vch_Name as FacilityName,
units.uni_int_unitid,
units.uni_vch_unitno,
units.uni_int_status,
units.uni_bit_deleteflag,
unittypes.uty_int_Id,
unittypes.uty_vch_code,
unittypes.uty_int_length,
unittypes.uty_int_width,
unittypes.uty_bit_deleteflag,
unittyperent.futr_mny_MonthlyRent,
tenantunitleasedetails.tul_dtm_moveindate,
tenantunitleasedetails.tul_dtm_moveoutdate,
tenantunitleasedetails.tul_bit_transferin,
tenantunitrentraise.tur_mny_NewRent,
tenantunitleasedetails.tul_int_Leaseno,
units.uni_dtm_DateCreated,
unittyperent.futr_dtm_EffectiveDate
FROM
essm.dbo.Units units,
essm.dbo.FacilitySections sections,
essm.dbo.UnitTypes unittypes,
essm.dbo.FacilityUnitTypesRent unittyperent,
essm.dbo.TenantUnitLeases tenantunitleasedetails,
essm.dbo.StorageFacility,
--
essm.dbo.TenantUnitRentRaise tenantunitrentraise
--
WHERE
uni_int_SectionId = fse_int_FacilityId AND
uni_int_UnitTypeId=uty_int_Id and
uty_int_Id=futr_int_UnitTypeId and
--Left Outer Join
--uni_int_UnitId *=tul_int_UnitId and
uty_bit_DeleteFlag=0 AND
futr_bit_DeleteFlag = 0 AND
uni_bit_DeleteFlag=0 AND
fse_bit_DeleteFlag=0 AND
stf_int_FacilityId = fse_int_FacilityId and
tul_int_UnitId IN (
SELECT tul_int_UnitId
FROM essm.dbo.TenantUnitLeases
WHERE tul_int_FacilityId =sections.fse_int_FacilityId) AND
futr_int_FacilityId = fse_int_FacilityId AND
futr_dtm_EffectiveDate = (
SELECT MAX(futr_dtm_EffectiveDate)
FROM essm.dbo.FacilityUnitTypesRent
WHERE uty_int_Id = futr_int_UnitTypeId AND
futr_int_FacilityId = fse_int_FacilityId AND
futr_bit_DeleteFlag = 0) AND
uty_int_Id IN (
SELECT futd_int_UnitTypeId
FROM essm.dbo.FacilityUnitTypesDeposit
WHERE futd_int_FacilityID =fse_int_FacilityId AND
futd_bit_DeleteFlag = 0)
) AS RenAct
ORDER BY FacilityName ASC
;


"Experience is something you don't get until just after you need it." - Steven Wright

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-15 : 08:30:38
which tables contain fields uni_int_UnitId & tul_int_UnitId?
Go to Top of Page

James.Hastings
Starting Member

4 Posts

Posted - 2009-01-15 : 08:35:18
uni_ = dbo.Units
tul_ = dbo.TenantUnitLeases

"Experience is something you don't get until just after you need it." - Steven Wright
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-15 : 08:49:12
[code]
SELECT
fse_int_FacilityId as FacilityID,
stf_vch_Name as FacilityName,
units.uni_int_unitid,
units.uni_vch_unitno,
units.uni_int_status,
units.uni_bit_deleteflag,
unittypes.uty_int_Id,
unittypes.uty_vch_code,
unittypes.uty_int_length,
unittypes.uty_int_width,
unittypes.uty_bit_deleteflag,
unittyperent.futr_mny_MonthlyRent,
tenantunitleasedetails.tul_dtm_moveindate,
tenantunitleasedetails.tul_dtm_moveoutdate,
tenantunitleasedetails.tul_bit_transferin,
tenantunitrentraise.tur_mny_NewRent,
tenantunitleasedetails.tul_int_Leaseno,
units.uni_dtm_DateCreated,
unittyperent.futr_dtm_EffectiveDate
FROM
essm.dbo.Units units,
JOIN essm.dbo.FacilitySections sections
ON ....
JOIN essm.dbo.UnitTypes unittypes
ON....
JOIN essm.dbo.FacilityUnitTypesRent unittyperent
ON...
LEFT JOIN essm.dbo.TenantUnitLeases
ON uni_int_UnitId =tul_int_UnitId

..........
[/code]
Go to Top of Page

James.Hastings
Starting Member

4 Posts

Posted - 2009-01-15 : 09:33:26
Does it make a difference that the old join was in the "Where" conditions not in the "From"?

"Experience is something you don't get until just after you need it." - Steven Wright
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-15 : 09:37:40
For inner joins, it wouldn't make a difference.
Go to Top of Page

James.Hastings
Starting Member

4 Posts

Posted - 2009-01-15 : 09:43:28
what about left outer joins

"Experience is something you don't get until just after you need it." - Steven Wright
Go to Top of Page
   

- Advertisement -