Simple Store Procedure Code Example

USE [DataBaseNameUsing]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[sp_TEST] -- Stored Procedure name
AS
BEGIN
set nocount on

-- ================ Declare parameter for query data from table source
declare @MonthforDelete decimal(18, 0)
 declare @YearforDelete nvarchar(10)
declare @ID nvarchar(10)
declare table_tmp cursor for

-- ================ Select data from table souce by unique year,month and ID
SELECT DISTINCT field_month,field_year,ID

FROM DataBaseNameSource..Table_Source

open table_tmp

-- ================ Save all select data as condition into table temp
fetch next from table_tmp
into @MonthforDelete,@YearforDelete,@ID

-- ================ Delete data from destinatin table
while @@fetch_status = 0
begin
DELETE FROM DataBaseNameDestination..Table_DataFact
WHERE ID = @ID
AND field_month = @MonthforDelete
AND field_year = @YearforDelete
fetch next from table_tmp
into @MonthforDelete,@YearforDelete,@ID
end

close table_tmp

deallocate table_tmp
END


Good Word to improve myself

Long distant we will get the aim by keep moving forward.

Not thing can make you feel suffering, It's depend on your point of view about that experience.

Every morning and before you sleep, You have to say thank you for every things to came to your life, even it will was good or bad ^_^.

Do the thing as you like, It will become the right one.

How do you know it's right if you never did wrong first!

Forget the pass then start the new ^_^.

Good leader you have to prove yourself by how much you make employ respect you with love, it's not to make people under you as command.

Keep moving forward, do not look back, it's just your a part of your life.