Reputation: 53
I have two tables. They are:
Country(CountryID,CountryName,AboutCountry)
City(CityID,CityName,Location,AboutCity,CountryID)
They are in One-to-many relationship(From Country's perspective). I created a view like this
CREATE VIEW GetByID AS
SELECT DISTINCT CountryName FROM
City INNER JOIN Country ON
City.CountryID = Country.CountryID
I am getting this error called multi-part identifier could not be bound after executing this query
SELECT * FROM GetByID WHERE City.CityID = 1
I used 1 because I know CityID = 1 belongs a city from the city table. If I execute without using the view then I don't get that error anymore. Why this error is happening? Could someone please explain this error and how can I avoid this kind of error?
Thanks in advance.
Upvotes: 0
Views: 282
Reputation: 15150
You create a view with only CountryName
as field. And then you are searching for CityID
which isn't in your view. It seems you are approaching your view as a procedure. You should treat it as a table, it's created with fields, and you can't query whats not already there. You should expand your view to include CityID
.
Upvotes: 2