Hello in the statement below I have 2 variables that I set manually, I need to execute this statement up to present month and year.
How could I accomplish this without manually setting the year and month each time, can anyone explain what I need to do or help. Thank you for taking time.
DECLARE @ReleaseMonth varchar(10)
DECLARE @ReleaseYear varchar(10)
SET @ReleaseMonth ='January'
SET @ReleaseYear = '2000'
INSERT INTO MATRIX
SELECT @ReleaseMonth AS'Month_Released'
,@ReleaseYear AS 'Year_Released'
,COUNT(AR.Offender_Number)TotalOffendersReleased
,SUM(LengthOfStay) AS [TotalDays]
,SUM(CONVERT(DECIMAL(10,2),LengthOfStay))/Count(AR.Offender_Number)AS [Average Length of Stay]
FROM Admission_Release AR INNER JOIN
Offenders O ON AR.Offender_Number = O.Offender_Number
WHERE ReleaseMonth= @ReleaseMonth AND ReleaseYear=@ReleaseYear
AND AR.Release_Age >= 18
How could I accomplish this without manually setting the year and month each time, can anyone explain what I need to do or help. Thank you for taking time.
DECLARE @ReleaseMonth varchar(10)
DECLARE @ReleaseYear varchar(10)
SET @ReleaseMonth ='January'
SET @ReleaseYear = '2000'
INSERT INTO MATRIX
SELECT @ReleaseMonth AS'Month_Released'
,@ReleaseYear AS 'Year_Released'
,COUNT(AR.Offender_Number)TotalOffendersReleased
,SUM(LengthOfStay) AS [TotalDays]
,SUM(CONVERT(DECIMAL(10,2),LengthOfStay))/Count(AR.Offender_Number)AS [Average Length of Stay]
FROM Admission_Release AR INNER JOIN
Offenders O ON AR.Offender_Number = O.Offender_Number
WHERE ReleaseMonth= @ReleaseMonth AND ReleaseYear=@ReleaseYear
AND AR.Release_Age >= 18