USE [ARSystem]
GO
/****** Object:  UserDefinedFunction [dbo].[DateOnlyInt_to_datetime]    Script Date: 04/10/2008 17:00:57 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE FUNCTION [dbo].[DateOnlyInt_to_datetime] (@dateint int)
RETURNS DATETIME AS
BEGIN
	DECLARE @sql_date	datetime;
	-- SQL Server datetime values begin at 01/01/1753
	-- Remedy Date-only values begin at 01/01/4713 B.C.
	-- Remedy Date-only integer value for 01/01/1753 is 2361331
	IF @dateint < 2361331
		SET @sql_date = '17530101'
	ELSE
		SET @sql_date = DATEADD(dd,@dateint - 2361331,'17530101');
	RETURN @sql_date;
END