January 23, 2007 at 12:01 pm
Hi,
I am trying to run a very simple query of a table.
select *
from gentiva1407
where gentiva1407.locationcode <> gentiva1206.locationcode
When I run it, I get the following error:
Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'gentiva1206' does not match with a table name or alias name used in the query.
That can't be right because I know the table is there and populated. Also, I verified that LocationCode is in both tables.
I feel so stupid! Why doens't this stuff work the way I think it should?
Thanks in advance for your help...
David
January 23, 2007 at 12:08 pm
You have not included the table gentiva1206 in the from part of the query so you cannot reference it like this in the where clause.
I'm not totally sure what you want to find out but I am guessing that you want records in gentiva1407 that are not in gentiva1206 if so this would work
SELECT *
FROM gentiva1407 g1407
WHERE NOT EXISTS (SELECT * from gentiva1206 g1206 where g1206.locationcode = g1407.locationcode)
hth
David
P.S if this isn;t what you are attempting to achieve then if you clarify what you want I am sure one of us will give a hand
January 23, 2007 at 1:20 pm
OK, what I am trying to do is see if there are any location codes in gentiva1407 that are not in gentiva1206, and if so, return all the data that is in that record.
January 29, 2007 at 3:33 pm
select *
from gentiva1407
where locationcode not in
(select locationcode from gentiva1206)
January 29, 2007 at 8:09 pm
Check the ownership of this table. If it is not dbo, you may have to include the ownership in front of your table name.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply