This is my table:
CREATE TABLE [dbo].[InvoiceTable] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[CodeColumn] NVARCHAR (50) NOT NULL,
[NameColumn] NVARCHAR (50) NOT NULL,
[QTYColumn] INT NULL,
[TotalQTYColumn] INT NULL,
[UnitCostColumn] INT NOT NULL,
[TotalCost] INT NULL,
[DiscountRateColumn] FLOAT (53) DEFAULT ((0)) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
I want something like this:
SELECT
CodeColumn,
NameColumn
TotalQTYColumn = SUM(QTYColumn
TotalCost = SUM(UnitCostColumn)*SUM(QTYColumn))
blah
FROM InvoiceTable
This doesnt solve my problem:
select
blah
SUM(UnitCostColumn)*SUM(QTYColumn) AS TotalCost
SUM(QTYColumn) AS TotalQTYColumn,
blah
cause I want to add the resualt to an existing column in my table not something new...
this didnt work for me:
SELECT
CodeColumn,
NameColumn,
(select TotalQTYColumn = SUM(QTYColumn))
UnitCostColumn,
DiscountRateColumn,
(select TotalCost = SUM(UnitCostColumn)*SUM(QTYColumn))
FROM InvoiceTable
GROUP BY CodeColumn, NameColumn, UnitCostColumn, DiscountRateColumn
I dont know why it doesnt show the results in TotalCost Column and TotalQTY column when I want to see the results on a datagridview.