SELECT qi.ItemNo
,ISNULL(qi.description, '') AS Description
,ISNULL(qi.Qty, 0) AS Qty
,qi.Price
,SUM(qi.Qty * qi.Price) AS ExtPrice
FROM dbo.QuoteItem qi (NOLOCK)
INNER JOIN dbo.Quote q (NOLOCK)
ON (qi.QuoteNo = q.QuoteNo)
LEFT OUTER JOIN dbo.Inventory i (NOLOCK)
ON (qi.serialno = i.serialno)
WHERE
q.SalesNo = '2328719529'
AND m.itemtype NOT IN ('L','F','S')
AND qi.warrantyflag <> 'Y'
AND qi.ITEMTYPE NOT IN ('SUBHEAD','COMMENT','BLANK','SUBTOTAL')
AND qi.statuscode NOT IN ('CANCELLED','CANCELED')
AND q.statuscode NOT IN ('CLOSED')
AND ISNULL(m.prodtype,'')=''
AND isNull(qi.Printflag, '') = 'Y'
GROUP BY qi.ConItemNo
,qi.Description
,qi.Qty
,qi.Price
WITH ROLLUP
ORDER BY qi.ConItemNo DESC
这是我期待的结果集
ConItemNo Description Qty Price ExtPrice Format
1 test1 1 100 100
2 test2 2 200 400
3 test3 3 300 900
4 test4 1 100 100
5 test5 2 100 200
Subtotal 1700 B
Total 1700 U,B
有什么建议吗? “格式”列不属于任何表,之后添加。我正在考虑将QuoteItems添加到临时表并在之后修改数据。我只是不确定如何解决这个问题。任何建议将非常感谢。我试图在Microsoft SQL Server 2016中完成此任务。
谢谢!