Table structure
CREATE TABLE [dbo].[StackQuestion]
(
[ID] [BIGINT] IDENTITY(1,1) NOT NULL,
[Product_Id] [BIGINT] NULL,
[Quantity] [DECIMAL](18, 6) NULL,
[Description] [NVARCHAR](MAX) NULL,
CONSTRAINT [PK_StackQuestion]
PRIMARY KEY CLUSTERED ([ID] ASC)
)
Demo data
INSERT [dbo].[StackQuestion] ([ID], [Product_Id], [Quantity], [Description])
VALUES (1, 10, CAST(50.000000 AS Decimal(18, 6)), N'Description1'),
(2, 20, CAST(10.000000 AS Decimal(18, 6)), N'StackDesc'),
3, 10, CAST(10.000000 AS Decimal(18, 6)), N'Descrip2')
GO
So basically I need to group those columns by product id and sum their total quantity. And I can do that by a simple query such as
SELECT
MAX(ID) AS LastID, Product_Id, SUM(Quantity) AS Quantity
FROM
stackquestion
GROUP BY
Product_Id
The point is how to get total description of all items in that group. My description column needs to contain all descriptions in that group (SUM of nvarchar)
Output should be something like this: