Hello Everyone,
I have this code in SQL that I use for percentage in VB.net but, I need to replace the NULL values to 0 in SQL so I don't have any troubles in Vb.net forms. This is the SQL code :
DECLARE @Year1 DECIMAL,@Year2 DECIMAL,@Current VARCHAR(7),@Previous VARCHAR(7)
SET @Current='2020-03'
SET @Previous =CAST(SUBSTRING(@Current,1,6) AS VARCHAR(5)) + RIGHT('0' + CAST(SUBSTRING(@Current,6,2) - 1 AS VARCHAR(2)),2)
SELECT @Year1 = Sum(Price) FROM dbo.Expenses WHERE CONVERT(char(7), date, 120) = @Previous AND Department IN ('Grocery','Department','FixCost','Clothes','Other','Vacation')
SELECT @Year2 = Sum(Price) FROM dbo.Expenses WHERE CONVERT(char(7), date, 120) = @Current AND Department IN ('Grocery','Department','FixCost','Clothes','Other','Vacation')
SELECT 100.0*(@Year2 - @Year1) / @Year1 As PercentageDiff
And when there are empty values I would like to have as result 0 and not NULL.
Thank you, Best REgards