คือเขียนคิวรี่ไว้อย่างนี้ค่ะ
SELECT OrderNo,[LineNo],StructLineNo ,Sum(qtydelscunit+qtyinvpcunit) as TotalDel
Into [PCDelInfo]
FROM scaladb3.dbo.[V-PC1901-Order Line Del]
group by OrderNo,[LineNo],StructLineNo
Select distinct a.PurchaOrdNo,a.LineNumber,a.StockCode,a.structLineNo,
(a.pcqtyordered+a.pcqtyreceive+a.pcqtyinvoice) as TotalOrder,c.TotalDel,((a.pcqtyordered+a.pcqtyreceive+a.pcqtyinvoice)-c.totalDel) as Pending_PO
from scaladb3.dbo.[V-PC0301-PO Line File] a
Left join [PCDelInfo] c on a.PurchaOrdNo = c.OrderNo and a.LineNumber = c.[LineNo] and a.StructLineNo = c.StructLineNO
Left join scaladb3.dbo.[V-PC1901-Order Line Del] b on a.PurchaOrdNo = b.OrderNo and a.LineNumber = b.[LineNo] and a.StructLineNo = b.StructLineNO
where
(a.pcqtyordered+a.pcqtyreceive+a.pcqtyinvoice) <> c.TotalDel
order by a.PurchaOrdNo,a.LineNumber
แล้วอยากจะสร้างในวิว รันคิวรี่ก็ผ่านค่ะไม่มีปัญหา แต่พอใส่คำสั่ง ครีเอทวิว มันฟ้อง error ว่า
Incorrect syntax near the keyword 'Into'.
ต้องแก้ไขอย่างไรหรอคะ
SELECT OrderNo,[LineNo],StructLineNo ,Sum(qtydelscunit+qtyinvpcunit) as TotalDel
Into [PCDelInfo]
FROM scaladb3.dbo.[V-PC1901-Order Line Del]
group by OrderNo,[LineNo],StructLineNo
SELECT OrderNo,[LineNo],StructLineNo ,Sum(qtydelscunit+qtyinvpcunit) as TotalDel
Into [PCDelInfo]
FROM scaladb3.dbo.[V-PC1901-Order Line Del]
group by OrderNo,[LineNo],StructLineNo, TotalDel
ต้องเพิ่มนี่นิดหนึ่ง เนื่องจากใช้ group by คุณต้องใส่ field group by ให้ครบ