subquerie problem.
Vær hilset!SELECT
inventtable.itemid as inventtableitemid,custvendexternalitem.itemid as custvendexternalitemitemid,
t2.itemrelation as pricedisctableitemrelation,inventtable.fabrikat,inventtable.netweight,
inventtable.intracode, custvendexternalitem.externalitemid,inventtable.primaryvendorid,
t2.accountrelation,custvendexternalitem.custvendrelation,t2.amount,
t2.currency,t2.deliverytime,t2.priceunit,t2.percent1,t2.unitid,t2.fromdate
FROM inventtable
INNER JOIN
(
SELECT fromdate,todate,percent1,unitid,itemrelation,amount,deliverytime,priceunit,
currency,accountrelation
FROM pricedisctable
WHERE todate = '1900-01-01' AND accountrelation = '44948700'
AND fromdate =
(
SELECT MAX(fromdate)
FROM pricedisctable
WHERE todate = '1900-01-01'
AND accountrelation = '44948700'
AND itemrelation = inventtable.itemid
)
) AS t2
ON (t2.itemrelation = inventtable.itemid)
INNER JOIN custvendexternalitem ON ( custvendexternalitem.itemid = inventtable.itemid )
WHERE custvendexternalitem.custvendrelation = '44948700'
AND inventtable.itemid = '048-1476318'
AND t2.accountrelation = custvendexternalitem.custvendrelation
AND inventtable.primaryvendorid = ' 44948700' AND inventtable.dataareaid = 100
ORDER BY inventtable.primaryvendorid
Jeg får fejlen:
Server: Msg 107, Level 16, State 3, Line 3
The column prefix 'inventtable' does not match with a table name or alias name used in the query.
Mit mål er at hente den nyeste post fra pricedisctable hvis de overholder mine kriterier. Dvs. den skal hente den nyeste fromdate som fx. har et itemrelation og accountrelation der matcher med den i inventtable.