I am having issues with the following:
INSERT INTO [##PH_Results] (NAMEKEY, QTYSOLD, PRODUCT)
(
SELECT TOP 25 dbo.InvDetail.OMItemKey, SUM(dbo.InvDetail.OMItemQty) AS TotalCount,
dbo.Inventory.PRODUCT FROM dbo.InvHeader INNER JOIN dbo.InvDetail ON dbo.InvHeader.OMInvoiceNumber = dbo.InvDetail.OMInvoiceNumber
INNER JOIN dbo.Inventory ON dbo.InvDetail.OMItemKey = dbo.Inventory.NAMEKEY
WHERE (dbo.InvHeader.OMVoid = 0) AND (dbo.InvHeader.OMDate
BETWEEN '12/01/2006' AND '12/29/2006 23:59:59')
GROUP BY dbo.InvDetail.OMItemKey, dbo.InvDetail.OMItemDesc, dbo.Inventory.PRODUCT
ORDER BY SUM(OMItemQty) DESC
)
I run the query alone and its fine. Results that I need but when I dump it to the temp table I get error at ORDER. Am I not allowed to do this?
INSERT INTO [##PH_Results] (NAMEKEY, QTYSOLD, PRODUCT)
(
SELECT TOP 25 dbo.InvDetail.OMItemKey, SUM(dbo.InvDetail.OMItemQty) AS TotalCount,
dbo.Inventory.PRODUCT FROM dbo.InvHeader INNER JOIN dbo.InvDetail ON dbo.InvHeader.OMInvoiceNumber = dbo.InvDetail.OMInvoiceNumber
INNER JOIN dbo.Inventory ON dbo.InvDetail.OMItemKey = dbo.Inventory.NAMEKEY
WHERE (dbo.InvHeader.OMVoid = 0) AND (dbo.InvHeader.OMDate
BETWEEN '12/01/2006' AND '12/29/2006 23:59:59')
GROUP BY dbo.InvDetail.OMItemKey, dbo.InvDetail.OMItemDesc, dbo.Inventory.PRODUCT
ORDER BY SUM(OMItemQty) DESC
)
I run the query alone and its fine. Results that I need but when I dump it to the temp table I get error at ORDER. Am I not allowed to do this?