Professional Documents
Culture Documents
GO
/****** Object: StoredProcedure [dbo].[Data_Cleansing]
12/25/2013 16:55:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
<Author,,Name>
-- Create date: <Create Date,,>
-- Description:
<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Data_Cleansing]
@No_YYYY [numeric](18, 0),
@No_MM [numeric](18, 0)
AS
BEGIN
Script Date:
and
and
and
and
and
no_mm = 9
col_id =1
company_id = 25
line_id =24
rep_id =5
INTO [Insurance].[dbo].[Companies_Data_Clean]
([No_YYYY]
,[No_MM]
,[Company_Id]
,[Rep_Id]
,[Line_Id]
,[Col_Id]
,[Data_Figure]
,[Snapshot_Date]
,[Data_Figure_Clean])
VALUES
(2013,9,22,5,24,1,200000,null,200000)
end
-----------------Add one row for company 23 if not exists
******/
,[Data_Figure_Clean]
FROM [Insurance].[dbo].[Companies_Data_Clean]
where no_yyyy =2013
and no_mm = 9
and col_id =1
and company_id = 25
and line_id =24
and rep_id =5))
BEGIN
INSERT
INTO [Insurance].[dbo].[Companies_Data_Clean]
([No_YYYY]
,[No_MM]
,[Company_Id]
,[Rep_Id]
,[Line_Id]
,[Col_Id]
,[Data_Figure]
,[Snapshot_Date]
,[Data_Figure_Clean])
VALUES
(2013,9,25,5,24,1,100000,null,100000)
end
update [Insurance].[dbo].[Companies_Data_Clean]
set data_figure = 100000 , data_figure_clean =100000
where rep_id =5
and company_id = 25
and line_id = 25
and no_yyyy =2013
and no_mm = 9
and col_id =1
update [Insurance].[dbo].[Companies_Data_Clean]
set data_figure = 200000 , data_figure_clean =200000
where rep_id =5
and company_id = 22
and line_id = 25
and no_yyyy =2013
and no_mm = 9
and col_id =1
-------
--Concatenate Year and Month to create a DateTime for 28th of the Month
update Companies_data_clean set Snapshot_Date =
cast(rtrim(ltrim(No_YYYY)) +'-'+ rtrim(ltrim(No_MM)) +'-'+ '28' AS
DATETIME)
---Remove '--'
Update Companies_data_clean
Set Data_Figure_Clean = replace(ltrim(rtrim(Data_Figure_Clean)), '--',
'')
----Update Some Records
END