Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

The multi-part identifier "i.orderid" could not be bound.

SELECT
p.productid,p.title, (ISNULL(CAST(P_Cnt.prod_Cnt AS VARCHAR(20)), 'No Orders'))as aquantity,p.internalsku,p.internalsku2,p.internalsku3,p.folderid,p.inwarehouse,p.inwarehouse2,p.inwarehouse3,p.ourinwarehouse,p.ourinwarehouse2,p.ourinwarehouse3,p.sentquantity,p.sentquantity2,p.sentquantity3,p.estimatedcost,p.cost2,p.cost3,date,date2,date3,estimateddate,estimateddate2,estimateddate3
from products p
left outer join (
select p2.productid, count(*) prod_Cnt from orderitems i
inner join orders o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products p2 on i.productid = p2.productid
where o.statusid in (9,10,90,180,260)
group by p2.productid)
P_Cnt on p.productid = P_Cnt.productid
where p.folderid = 119 order by p.productid desc

works

but in select statement, when I want to display i.orderid
I get an error





SELECT
p.productid,p.title, (ISNULL(CAST(P_Cnt.prod_Cnt AS VARCHAR(20)), 'No Orders'))as aquantity,p.internalsku,p.internalsku2,p.internalsku3,p.folderid,p.inwarehouse,p.inwarehouse2,p.inwarehouse3,p.ourinwarehouse,p.ourinwarehouse2,p.ourinwarehouse3,p.sentquantity,p.sentquantity2,p.sentquantity3,p.estimatedcost,p.cost2,p.cost3,date,date2,date3,estimateddate,estimateddate2,estimateddate3,i.orderid
from products p
left outer join (
select p2.productid, count(*) prod_Cnt from orderitems i
inner join orders o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products p2 on i.productid = p2.productid
where o.statusid in (9,10,90,180,260)
group by p2.productid)
P_Cnt on p.productid = P_Cnt.productid
where p.folderid = 119 order by p.productid desc


Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "i.orderid" could not be bound.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

that's normal, because your subselect you LEFT JOIN to does not return "orderid", AND is not aliases "i" neither

the question is: which row/value or orderid do you want to return?
Avatar of rgb192

ASKER


is there any way to return rows of products table and orderitems table


the query currently only returns products table

>is there any way to return rows of products table and orderitems table
sure, you only have to define what "join"/relationship you want to apply for the query, aka what output you want.
I don't have a crystal ball, so you have to give some "specs"
Avatar of rgb192

ASKER

i.orderid, i.productid from orderitems table table
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks