I am trying to use a joined table column that happens to also be aliased in a where clause.
My query is slightly more complex than this but here is the essence:
SELECT a.Name, b.Name AS xName
FROM TableA a
LEFT JOIN TableB b ON a.id=b.aid
WHERE a.Name LIKE @Filter OR b.Name LIKE @Filter
Throws error: The multi-part identifier 'b.Name' could not be bound
EDIT:
Resolved. I would delete this question but I do not know how to do that.
The error was not thrown by this query but by one based on it to get the total record count for use in a paged table.
So the query throwing the error was:
SELECT COUNT(*) AS total
FROM TableA a
WHERE a.Name LIKE @FilterValue OR b.Name LIKE @FilterValue
Which of course won't work.
But this does:
SELECT COUNT(*) AS total
FROM TableA a
LEFT JOIN TableB b ON a.id=b.aid
WHERE a.Name LIKE @FilterValue OR b.Name LIKE @FilterValue