I have some tables I’ve joined together in a view and I execute the view when I want to pull the result. I want to apply a where clause to the view so that my results provided by the view are filtered, however when I do this I get the error The multi-part identifier could not be bound.
When take the SQL query from the view and run it as a standalone query with my where clause it runs fine, so I have a problem with applying the where clause to my view.
View
SELECT
dbo.Assets.assetid, dbo.Assets.assetcommonname, dbo.Assets.assetcode,
dbo.Assets.assetserial, dbo.Assets.assetinternallocation, dbo.Assets.assetmodel,
dbo.Assets.assetmake, dbo.Assets.assetmac, dbo.Assets.assetnotes,
dbo.AssetTypes.typename, dbo.Locations.locationame, dbo.Customers.customername,
dbo.Routes.routename, dbo.Locations.customerid
FROM
dbo.Assets
INNER JOIN
dbo.AssetTypes ON dbo.Assets.assettype = dbo.AssetTypes.typeid
INNER JOIN
dbo.Locations ON dbo.Assets.assetlocation = dbo.Locations.locationid
INNER JOIN
dbo.Customers ON dbo.Locations.customerid = dbo.Customers.customerid
INNER JOIN
dbo.Routes ON dbo.Locations.locationroute = dbo.Routes.routeid
How I execute the view with my where clause
select * from afViewassetlinked where (Locations.customerid = '1')
what have I done wrong?
Change
to
The view
afViewassetlinkedis not the tableLocations.