Question : SQL Server query issue with inner and outer joins

I have a proc that this query below is running.  If I run just the SQL I get "the multipart identifier could not be bound"

Tables have the columns but the result is an error?  Im an Oracle guy looking shaking my head.  the query has a where clause and at the end are the two statements I am trying to implement on the top two rows of the where clause (with SQL Server syntax).

The bottom two are inner joins but need to be outer join as illustrated in the top two lines.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
declare @i_Prefix  as varchar(200)
set @i_Prefix = '' 
declare @i_FirstName as varchar(200)
set @i_FirstName = '' 
declare @i_MiddleName as varchar(200)
set @i_MiddleName = '' 
declare @i_LastName as varchar(200)
set @i_LastName = '' 
declare @i_Suffix as varchar(200)
set @i_Suffix = '' 
declare @i_NickName as varchar(200)
set @i_NickName = '' 

SELECT 
	  TP.FirstName		
	, TP.LastName		
    , TA.Address1		
    , TA.City			
    , TA.StateProvince	
	FROM 
	  T_Person			        TP
    , T_Address			        TA
    , T_XREFPersonAddress		TXRPa
    inner join T_Address on T_Address.ID = T_XREFPersonAddress.IDAddress
    left outer join T_XREFPersonAddress on T_XREFPersonAddress.IDPerson = T_Person.IDPerson
	Where (lower(TP.Prefix) like (lower(@i_Prefix) + '%') OR TP.Prefix is null)
	  and (lower(TP.firstname) like (lower(@i_FirstName) + '%') OR TP.firstname is null)
      and (lower(TP.middlename) like (lower(@i_MiddleName) + '%') OR TP.middlename is null)
      and (lower(TP.lastname) like (lower(@i_LastName) + '%') OR TP.lastname is null)
      and (lower(TP.Suffix) like (lower(@i_Suffix) + '%') OR TP.Suffix is null)
      and (lower(TP.NickName) like (lower(@i_NickName) + '%') OR TP.NickName is null)
      --and TA.ID = TXRPa.IDAddress
      --and TP.IDPerson = TXRPa.IDPerson

Answer : SQL Server query issue with inner and outer joins


SELECT  
          TP.FirstName          
        , TP.LastName            
    , TA.Address1                
    , TA.City                    
    , TA.StateProvince  
        FROM  
          T_Person as TP
    left outer join T_XREFPersonAddress as TXRPa on TP.IDPerson=TXRPa.IDPerson
left join T_Address as TA on TA.ID = TXRPa.IDAddress
        Where (lower(TP.Prefix) like (lower(@i_Prefix) + '%') OR TP.Prefix is null)
          and (lower(TP.firstname) like (lower(@i_FirstName) + '%') OR TP.firstname is null)
      and (lower(TP.middlename) like (lower(@i_MiddleName) + '%') OR TP.middlename is null)
      and (lower(TP.lastname) like (lower(@i_LastName) + '%') OR TP.lastname is null)
      and (lower(TP.Suffix) like (lower(@i_Suffix) + '%') OR TP.Suffix is null)
      and (lower(TP.NickName) like (lower(@i_NickName) + '%') OR TP.NickName is null)
      --and TA.ID = TXRPa.IDAddress
      --and TP.IDPerson = TXRPa.IDPerson
Random Solutions  
 
programming4us programming4us