0
I have this querry that gives me the total number of lines that start with the same code
USE CCILCDatabase;
GO
DECLARE @mes int;
SET @mes = 1;
WHILE (select @mes) <= 12
BEGIN
SELECT LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2), COUNT(*)
FROM PublicContestCPV
where YEAR(DateCreated) = '2016' AND MONTH(DateCreated) = (select @mes) AND (PublicContestID in (SELECT ContestID FROM PublicContests where [UEPublicContestType] = ''))
GROUP BY LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2)
ORDER BY LEFT(CONVERT(VARCHAR(10),[CPVCodeID]),2)
SET @mes += 1;
END
PRINT @mes;
I needed, in addition to counting, to show the SUM()
one-column (Contractvalue) that’s on the table Publiccontests. My SQL is not very trained, and this querry I need seems impossible.
See if my answer suits you, to be more precise I would need the columns that grate the two tables.
– Caique Romero
See https://answall.com/questions/272917/trocar-while-por-group-em-sql
– José Diz