Reputation: 47
I have a table name with spaces between say like 'Orders Details'.
I want to use that table in stored procedures with joins.I have tried using alias names,[],`` in queries but nothing seems to be working.Can anybody help me on this error!
Upvotes: 1
Views: 2226
Reputation: 1269543
Do not use order
as a column alias. It is a SQL keyword. I would just use o
:
select o.*, od.*
from orders o join
order_details od
on o.orderid = od.orderid
where year(o.orderdate) = @orderyear;
Notes:
JOIN
condition is on ProductId
. However, that is highly suspicious. Usually such joins are on the order id. In fact, ProductId
doesn't belong in Orders
(usually) if there is a detail table.orderdate
does not seem to be defined, because it has a red underline.select *
. For one thing, you will have duplicate column names. More importantly, you want to be explicit about what this code returns, particularly in a stored function or procedure.Upvotes: 3