>Ciao a tutti,
Ciao!
>è una cosa che posso fare via SQL?
Osserva il seguente esempio:
USE tempdb;
GO
CREATE TABLE Quantita
(
ID int NOT NULL
, Campo1 varchar(10) NOT NULL
, Campo2 varchar(10) NOT NULL
, Qta smallint NOT NULL
)
GO
INSERT INTO Quantita
VALUES (1, 'a', 'b', 1)
INSERT INTO Quantita
VALUES (1, 'a', 'b', 4)
INSERT INTO Quantita
VALUES (2, 'a', 'b', 2)
INSERT INTO Quantita
VALUES (2, 'a', 'b', 5)
INSERT INTO Quantita
VALUES (3, 'a', 'b', 10)
INSERT INTO Quantita
VALUES (3, 'a', 'b', 6)
INSERT INTO Quantita
VALUES (3, 'a', 'b', 5)
GO
;WITH QuantitaTOT AS
(
SELECT
ID
, QuantitaTOT = SUM(Qta)
FROM
Quantita
GROUP BY
ID
)
SELECT
QT.ID
, Qta
, QT.QuantitaTOT
FROM
QuantitaTOT QT
JOIN Quantita Q ON Q.ID = QT.ID
/*
ID Qta QuantitaTOT
----------- ------ -----------
1 1 5
1 4 5
2 2 7
2 5 7
3 10 21
3 6 21
3 5 21
*/
-- pulizia
DROP TABLE Quantita
GO
ovviamente il campo della sommatoria è ripetuto per tutti i record, però puoi gestire applicativamente la logica di rottura.
>
>grazie!
di nulla!
>
>
Alx81 =)
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org