views:

8

answers:

2

I am trying an inner join like this.

select R.ReservationID, R.BookingNumber,P.FirstName, P.LastName  
from Reservation R inner join PersonName P 
on Reservation.ReservationID = PersonName.ResrvationID 

I am getting the errors as:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Reservation.ReservationID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "PersonName.ResrvationID" could not be bound.
+2  A: 

The aliases "R" and "P" masks the actual table name.

Although it does not apply here, it makes sense generally. For example, when you have a self join

select R.ReservationID, R.BookingNumber,P.FirstName, P.LastName  
from Reservation R inner join PersonName P 
on R.ReservationID = P.ReservationID --use aliasas
gbn
It works but what's the difference?
Nadeem
@Nadeem: Reservation.ReservationID does not exist because you used "R". What if you had Reservation twice for example?
gbn
+1 for the self join stuff
Nadeem
+1  A: 

Try instead

select 
  R.ReservationID
, R.BookingNumber
, P.FirstName
, P.LastName   

from Reservation R 
inner join PersonName P  
on R.ReservationID = P.ResrvationID  
Noel Abrahams