

CREATE PROCEDURE [dbo].[AccountMonthTurnover] @Month Varchar(2), @Year Varchar(4), @AccountNumber int, @Amount Money = 0 OUTPUT AS
SET NOCOUNT ON

-- Denne procedure skal sammentælle alle TurnoverDebit-TurnoverCredit for en hel måned på en AccountDaily

IF LEN(@Month) = 2 --Hvis @Month f.eks. er af typen '01' for januar 
  SELECT SUM(Turnoverdebit) - SUM(TurnoverCredit) AS 'TurnoverMonth' FROM AccountDaily WHERE AccountNumber = @AccountNumber AND [Date] LIKE(@Year+@Month+'__')
else --Hvis @Month f.eks. er af typen '1' for januar
  SELECT SUM(Turnoverdebit) - SUM(TurnoverCredit) AS 'TurnoverMonth' FROM AccountDaily WHERE AccountNumber = @AccountNumber AND [Date] LIKE(@Year+'0'+@Month+'__')

