I have the following query:

```
SELECT dbo.saleDocumentDetails.ID,
       dbo.saleDocumentDetails.DocumentID,
       dbo.saleDocumentDetails.invProductID,
       dbo.saleDocumentDetails.Qty,
       dbo.saleDocumentDetails.QtyConfirmed,
       dbo.saleDocumentDetails.AmountPrice,
       dbo.saleDocumentDetails.AmountUserPrice,
       dbo.saleDocumentDetails.AmountCost,
       dbo.saleDocumentDetails.RespiteDays,
       dbo.saleDocumentDetails.Date_UpdateLast,
       CASE 
            WHEN io1.Code = '33' THEN SUM(idd.Qty)
            ELSE SUM(0)
       END                               AS Qty_BackSale,
       CASE 
            WHEN io1.Code = '41' THEN SUM(idd.Qty)
            ELSE SUM(0)
       END                               AS Qty_Stock
FROM   dbo.saleDocuments
       INNER JOIN dbo.saleDocumentDetails
            ON  dbo.saleDocuments.ID = dbo.saleDocumentDetails.DocumentID
       LEFT OUTER JOIN dbo.invDocumentDetails   AS  idd
            ON  dbo.saleDocumentDetails.ID = idd.saleDocumentDetailID
       LEFT OUTER JOIN dbo.invDocuments  AS id2
            ON  id2.ID = idd.invDocumentID
       LEFT JOIN dbo.invOperations       AS io1
            ON  (io1.ID = id2.invOperationID)
WHERE  (dbo.saleDocumentDetails.ID = 1295617)
GROUP BY
       dbo.saleDocumentDetails.ID,
       dbo.saleDocumentDetails.DocumentID,
       dbo.saleDocumentDetails.invProductID,
       dbo.saleDocumentDetails.Qty,
       dbo.saleDocumentDetails.QtyConfirmed,
       dbo.saleDocumentDetails.AmountPrice,
       dbo.saleDocumentDetails.AmountUserPrice,
       dbo.saleDocumentDetails.AmountCost,
       dbo.saleDocumentDetails.RespiteDays,
       dbo.saleDocumentDetails.Date_UpdateLast,
       io1.Code

```

its result is:

![enter image description here](https://i.stack.imgur.com/LMZpQ.png)

I would like to achieve:

![enter image description here](https://i.stack.imgur.com/RmzNu.png)

How should I change the query?