<!-- language: sql -->
IF OBJECT_ID('tempdb..#tempT') IS NOT NULL DROP TABLE #tempT
BEGIN
SELECT t1.id_Col, t2.route into #tempT
FROM soTran t1
LEFT JOIN armast t2
ON t1.custno = t2.custno
WHERE t1.orDate between DATEADD(day,-7, GETDATE()) and DATEADD(day,0, GETDATE())
EXCEPT ( SELECT a.id_col, c.route
FROM sotran a
INNER JOIN sotran b
ON a.custno = b.custno
LEFT JOIN armast c
ON a.custno = c.custno
WHERE a.ordate = b.ordate AND a.item = 'PLO' AND b.item <> 'PLO')
EXCEPT ( SELECT b.id_col, c.route
FROM sotran a
INNER JOIN sotran b
ON a.custno = b.custno
LEFT JOIN armast c
ON a.custno = c.custno
WHERE a.ordate = b.ordate AND a.item = 'PLO' AND b.item <> 'PLO' )
SELECT DISTINCT sono, q1.custno, item, q1.ordate, q1.salesmn, q2.company,(select route1 from #tempT)
FROM soTran q1
LEFT JOIN arcust q2
ON q1.custno = q2.custno
WHERE q1.id_col in (select id_col from #tempT) AND item = 'PLO' --AND q3.ordate between DATEADD(day,-7, GETDATE()) and DATEADD(day,0, GETDATE())
ORDER BY custno, ordate
DROP TABLE #tempT
END
我正在尝试从armast表中提取路径ID,该路径ID与此查询所提取的数据一致。由于某种原因,它没有提取正确的ID。