IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hashmd5]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE  FUNCTION [dbo].[hashmd5] (@data VARCHAR(10), @data2 VARCHAR(10))
  RETURNS BINARY(16) AS
	BEGIN
	DECLARE @hash BINARY(16)
	EXEC master.dbo.XP_MD5_EncodeKeyVal @data2, @data, @hash OUT
	RETURN @hash
	END'
END;