0
在查詢下面你將看到一個Item: 4500520400500
TSQL我不能日期添加適當的過濾器/ recid
在此查詢我想列出了最新的日期此項目的唯一規則10- 10-2016在這種情況下。或與最新RecID
我不能讓這與選擇中選擇querys工作。之前嘗試過 在這種情況下,我得到的所有物品,但我只想要最後的項目recid
。
我試過了WHERE Select MAX(RECID)
但是隻給出了整個表的記錄,而不是已經做出選擇的記錄。
SELECT A.DATAAREAID, A.ITEMID
, B.ACTIVATIONDATE, B.PRICE, B.CREATEDDATETIME, B.RECID
, 'DEFAULTORDERTYPE' = CASE
WHEN C.DEFAULTORDERTYPE = 0 THEN 'Purch'
WHEN C.DEFAULTORDERTYPE = 1 THEN 'Production'
WHEN C.DEFAULTORDERTYPE = 2 THEN 'Transfer'
WHEN C.DEFAULTORDERTYPE = 3 THEN 'Kanban'
ELSE 'Bestaat niet'
END
, 'PRODUCTTYPE' = CASE
WHEN D.PRODUCTTYPE = 1 THEN 'Item'
WHEN D.PRODUCTTYPE = 2 THEN 'Service'
ELSE 'Bestaat niet'
END
, E.MODELGROUPID AS 'Item Model Group'
FROM INVENTTABLE AS A
LEFT JOIN INVENTITEMPRICE AS B ON A.ITEMID = B.ITEMID AND A.PARTITION = B.PARTITION AND A.DATAAREAID = B.DATAAREAID
LEFT JOIN INVENTITEMSETUPSUPPLYTYPE AS C ON A.ITEMID = C.ITEMID AND A.DATAAREAID = C.ITEMDATAAREAID AND A.PARTITION = C.PARTITION
LEFT JOIN ECORESPRODUCT AS D ON A.PRODUCT = D.RECID AND A.PARTITION = D.PARTITION
LEFT JOIN INVENTMODELGROUPITEM AS E ON A.ITEMID = E.ITEMID AND A.DATAAREAID = E.ITEMDATAAREAID
WHERE A.KNK_ITEMHIDDEN = 0
AND (B.PRICE = 0 OR B.price IS NULL)
ORDER BY A.DATAAREAID, A.ITEMID, B.ACTIVATIONDATE