My sql server database has this stored procedure…
ALTER PROCEDURE [dbo].[NewBudget]
@year int,
@int nvarchar(3)
AS
BEGIN
SET NOCOUNT ON;
INSERT [NAOLI].[dbo].[BudgetsEditTbl]
([F_Year],[O_OrgCode],[O_OrgDesc],[S_SubObject],[S_SubDescrip],[B_BudgetAmt],[B_Initials],[B_CIPrefNo],[B_OrgBudgetAmt],[keyfield])
SELECT @year as [F_Year],[O_OrgCode],[O_OrgDesc],[S_SubObject],[S_SubDescrip], 0.00 as [B_BudgetAmt],@int as [B_Initials],null as [B_CIPrefNo],null as [B_OrgBudgetAmt],NewID()
FROM [NAOLI].[dbo].[BudgetsEditTbl]
END
What happends is according to the parameter ‘@year’ it automatically updates the database with records for the new year on the year change. Only instead of updating it with the new year, the orgcode and the corresponding subobject it gives me 6 records with the same orgcode. So it is essentially running the procedure 6 times and storing all that mess in my database. Any idea how I can fix this problem?
2011 | 536003 | Engineering | 6302 | Roads and Components | 0.00 | MC | N/A | 0.00
2011 | 536003 | Engineering | 6303 | Rights of Way -Acquire | 0.00 | MC | N/A | 0.00
2010 | 536003 | Engineering | 6302 | Roads and Components | 18300.00 | FG | N/A | 0.00
2010 | 536003 | Engineering | 6303 | Rights of Way -Acquire | 18300.00 | FG | N/A | 0.00
So for each year the same codes and info go in just different amounts…
You can use
DISTINCTto remove any duplicates