My subquery gives an error: Msg 102, Level 15, State 1, Line 17 Incorrect syntax near ')'.
SELECT SalesArea, Branch, Volume
from
(select
br.SalesArea as SalesArea
,br.Branch as Branch
, sum(a.Volume) as Volume
FROM dbo.vDetail a with (nolock)
LEFT JOIN
dbo.vBranch AS br WITH (nolock)
ON a.Branch = br.Branch
group by a.Volume, br.SalesArea, br.Branch)
You are missing alias for subquery try out this.
SELECT SalesArea, Branch, Volume
from
(select
br.SalesArea as SalesArea
,br.Branch as Branch
, sum(a.Volume) as Volume
FROM dbo.vDetail a with (nolock)
LEFT JOIN
dbo.vBranch AS br WITH (nolock)
ON a.Branch = br.Branch
group by a.Volume, br.SalesArea, br.Branch) as x
Every select from subquery needs an alias. Just add an "X" in the end that will become the name of the table
NOT OK:
select * from (
select * from your_table
)
OK:
select * from (
select * from your_table
) X
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With