
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- Pribadi Pamungkas. 2020-12-28
CREATE FUNCTION dbo.func_datetostring
(
	@pi_date DATE
)
RETURNS VARCHAR(50)
AS
BEGIN
	DECLARE @hasil VARCHAR(50)
	
	SELECT @hasil = CASE
					WHEN @pi_date IS NULL THEN NULL
					ELSE
						CAST(DAY(@pi_date) AS VARCHAR(2)) + ' ' +
							CASE MONTH(@pi_date)
								WHEN 1 THEN 'Januari'
								WHEN 2 THEN 'Februari'
								WHEN 3 THEN 'Maret'
								WHEN 4 THEN 'April'
								WHEN 5 THEN 'Mei'
								WHEN 6 THEN 'Juni'
								WHEN 7 THEN 'Juli'
								WHEN 8 THEN 'Agustus'
								WHEN 9 THEN 'September'
								WHEN 10 THEN 'Oktober'
								WHEN 11 THEN 'November'
								WHEN 12 THEN 'Desember' 
							END + ' ' +
							CAST(YEAR(@pi_date) AS VARCHAR(4))
				END

	RETURN @hasil

END
GO
