IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[CF_DB_Version]') 
                   and [type] = 'FN')
BEGIN
    DROP FUNCTION dbo.CF_DB_Version
END
GO

CREATE FUNCTION dbo.CF_DB_Version()
RETURNS DECIMAL(5,2)
AS
BEGIN

DECLARE @Ver				DECIMAL(5,2)
		,@ProductVersion	VARCHAR(128)

SET @ProductVersion = CONVERT(VARCHAR(18),SERVERPROPERTY('ProductVersion'))

IF @ProductVersion LIKE('8.%')
   SET @Ver = 8

IF @ProductVersion LIKE('9.%')
   SET @Ver = 9

IF @ProductVersion LIKE('10.%')
   SET @Ver = 10

IF @ProductVersion LIKE('10.25%')
   SET @Ver = 10.25

IF @ProductVersion LIKE('10.50%')
   SET @Ver = 10.50

IF @ProductVersion LIKE('11.%')
   SET @Ver = 11

IF @ProductVersion LIKE('12.%')
   SET @Ver = 12

IF @ProductVersion LIKE('13.%')
   SET @Ver = 13

IF @ProductVersion LIKE('14.%')
   SET @Ver = 14

IF @ProductVersion LIKE('15.%')
   SET @Ver = 15

IF @ProductVersion LIKE('16.%')
   SET @Ver = 16

IF @ProductVersion LIKE('17.%')
   SET @Ver = 17

IF @ProductVersion LIKE('18.%')
   SET @Ver = 18

IF @ProductVersion LIKE('19.%')
   SET @Ver = 19

IF @ProductVersion LIKE('20.%')
   SET @Ver = 20


RETURN ISNULL(@Ver, 0)
END