Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join query - column prefix does not match with table name

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Joined
Jan 26, 2006
Messages
392
Location
US
Hello,

I am running a select statement from Mytable1. I am joining:
tbldocumentinfo to mytable1
tblland to tbldocumentinfo
tblacreage to tblland

Selecting columns from all 4 tables works fine with the following query:

Code:
select col001, col002, col029, col030, col031, col032, col033, stownship, srange, tisection 
from mytable1
left join tcrgrand..tbldocumentinfo on col002 = tcrgrand..tbldocumentinfo.sdocumentno
left join tcrgrand..tblland on tcrgrand..tbldocumentinfo.irecordid = tcrgrand..tblland.irecordid
left join tcrgrand..tblacreage on tcrgrand..tblacreage.ilandid = tcrgrand..tblland.ilandid
order by col002

However if I put a column prefix at the beginning of one of my fields I get the error: The column prefix 'tblacreage' does not match with a table name or alias name used in the query.

For example, this query gives me the error (note the tblacreage prefix for tisection):
Code:
select col001, col002, col029, col030, col031, col032, col033, stownship, srange, tblacreage.tisection 
from mytable1
left join tcrgrand..tbldocumentinfo on col002 = tcrgrand..tbldocumentinfo.sdocumentno
left join tcrgrand..tblland on tcrgrand..tbldocumentinfo.irecordid = tcrgrand..tblland.irecordid
left join tcrgrand..tblacreage on tcrgrand..tblacreage.ilandid = tcrgrand..tblland.ilandid
order by col002

Am I doing something wrong where I can't use a column prefix? There is one column name duplicated in two tables and I want to specify the table I want it to come from. I can't get it to work without this column prefix.

Thanks for looking!
 
BTW ... This is SQL 2000.
 
I'm an idiot... I didn't specify my db name. The following worked:

Code:
select col001, col002, col029, col030, col031, col032, col033, stownship, srange, dbname..tblacreage.tisection 
from mytable1
left join tcrgrand..tbldocumentinfo on col002 = tcrgrand..tbldocumentinfo.sdocumentno
left join tcrgrand..tblland on tcrgrand..tbldocumentinfo.irecordid = tcrgrand..tblland.irecordid
left join tcrgrand..tblacreage on tcrgrand..tblacreage.ilandid = tcrgrand..tblland.ilandid
order by col002
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top