Using SQL functions
1 UseRDS2 GO3 4 --For ticket escaluation function.5 Insert intoSystemsettings (Name,value)VALUES('maxbatchsize','Ten')6 7 GO8 9 Ten /** * * * object: userdefinedfunction [dbo]. [Calcinterval] Script Date: 07/04/2008 11:46:26 * * * * * **/ One IF EXISTS(SELECT * fromSys.objectsWHERE object_id = object_id(N'[dbo]. [Calcinterval]') andTypeinch(N'FN'N'IF'N'TF'N'FS'N'FT')) A DROP FUNCTION [dbo].[Calcinterval] - GO - /** * * * object: userdefinedfunction [dbo]. [Calcinterval] Script Date: 07/04/2008 11:46:26 * * * * * **/ the SETAnsi_nulls on - GO - SETQuoted_identifier on - GO + IF not EXISTS(SELECT * fromSys.objectsWHERE object_id = object_id(N'[dbo]. [Calcinterval]') andTypeinch(N'FN'N'IF'N'TF'N'FS'N'FT')) - BEGIN + ExecuteDbo.sp_executesql@statement =N' A CREATE FUNCTION [dbo]. [Calcinterval] (@datepart varchar, @startdate varchar (), @enddate varchar ) at returns decimal - BEGIN - if Datepart ("minute", @startdate) > 0 or Datepart ("second", @startdate) > 0 OR Datepart ("Millisecond", @start Date) > 0 - BEGIN - SET @startdate = Dateadd ("hh", 1, @startdate) - END in - return DateDiff ("hh", @startdate, @enddate) to END' + END - the GO
SQL Create compute Time function