Hello! My issue is that my stored procedure only works if there is data in the table that it's referencing. For example: Table A: ----------------------------------Type | Totals ----------------------------------Active 0 Table B: ----------------------------------TotalActive------------------------------------5So basically if Table A's values are Null, that is there are no records with Type 'Active' in them, then it should show the Total Active column as 5, or do a subtraction 5-0(Null) = 5Here's my stored procedure: ALTER PROCEDURE [dbo].[GetDaysLeft]@ID intASDECLARE@DaysLeft float,@DaysTaken float,@TotalDays floatSET @DaysLeft = 0SET @DaysTaken = (SELECT SUM(DayType) from dbo.Tectonic WHEREType = 'Active' AND ID = @ID)SET @TotalDays = (SELECT Totals from dbo.Users WHERE ID = @ID)SET @Daysleft = @TotalDays - @DaysTakenSelect @DaysLeft AS FSDLeft
Just by itself, the stored procedure does the calculations properly, only when there is a record in Table A as 'Active', otherwise when there is no data then it doesn't return anything because there are no values in Table A stating 'Active'. It either doesn't return anything or it returns only 5 (which is the total in Table B) which is partially right, but when I put in a record stating Active in Table A, it again returns 5 instead of 4. This happened after I tried:(Select Coalesce(0, SUM(DayType)) from dbo.Tectonic Where Type = 'Active' AND ID = @ID)
Any ideas?