-- Create_Procedure.reference.usp_PopulateDays.sql

USE [Dates]
GO

-- if it doesn't exist, create the procedure
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Reference].[usp_PopulateDays]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [Reference].[usp_PopulateDays] AS SELECT 1' 
END
GO

-- always alter the procedure
ALTER PROCEDURE [Reference].[usp_PopulateDays] 
(	
	@truncate	bit = 1
) 
AS 

BEGIN 

SET NOCOUNT ON;

-- if necessary, truncate the table
IF (@truncate = 1)
BEGIN 
	TRUNCATE TABLE [Reference].[Days];
END;

-- populate the table
INSERT INTO [Reference].[Days] (
	DayNumber, DayEnglish, DayFrench, DayShortEnglish, DayShortFrench, DayInitialEnglish, DayInitialFrench,
	DayOfWeekNumber, IsWeekday, IsBusinessDay,
	CreatedBy, CreatedOn)
	VALUES
		(1, 'Monday',		'lundi',	'Mon', 'lun',	'M', 'l', 1, 1, 1, user_name(), getdate()),
		(2, 'Tuesday',		'mardi',	'Tue', 'mar',	'T', 'm', 2, 1, 1, user_name(), getdate()),
		(3, 'Wednesday',	'mercredi',	'Wed', 'mer',	'W', 'm', 3, 1, 1, user_name(), getdate()),
		(4, 'Thursday',		'jeudi',	'Thu', 'jeu',	'T', 'j', 4, 1, 1, user_name(), getdate()),
		(5, 'Friday',		'vendredi',	'Fri', 'ven',	'F', 'v', 5, 1, 1, user_name(), getdate()),
		(6, 'Saturday',		'samedi',	'Sat', 'sam',	'S', 's', 6, 0, 1, user_name(), getdate()),
		(7, 'Synday',		'dimanche',	'Sun', 'dim',	'S', 'd', 7, 0, 0, user_name(), getdate());		

SET NOCOUNT OFF;
END 

GO


