IF NOT EXISTS ( SELECT *  FROM   sysobjects WHERE id = object_id(N'[dbo].[CF_SCA_IdentifIdCliente]') AND [type] = 'FN')
BEGIN

EXECUTE dbo.sp_executesql @statement = N'

	CREATE FUNCTION [dbo].[CF_SCA_IdentifIdCliente](@pDato VARCHAR(100))
	RETURNS INT
	AS
	BEGIN
	DECLARE @Id_Cliente					INT

	IF(ISNULL(@pDato, '''') = '''')
	BEGIN
		SET @Id_Cliente = 0
		RETURN @Id_Cliente
	END


	SET @Id_Cliente = ISNULL((SELECT MAX(Id_Cliente) FROM Clientes WHERE Credencial_Nro = @pDato), 0)	
	RETURN @Id_Cliente

	RETURN ISNULL(@Id_Cliente, 0)

	END'

END
GO