IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'dbo.CP_Login_Extranet') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE dbo.CP_Login_Extranet 
END
GO

CREATE PROCEDURE [dbo].[CP_Login_Extranet]	@pEmail_Web VARCHAR(300),
											@pClave_Web VARCHAR(30)
AS
BEGIN


CREATE TABLE #Cliente_Valido	(Id_Cliente			INT,
								Apellido			VARCHAR(100),
								Nombre				VARCHAR(100),
								Razon_Social		VARCHAR(100),
								Email_Web			VARCHAR(300))

INSERT INTO #Cliente_Valido
SELECT TOP 1
Id_Cliente, 
ISNULL(Apellido, '') AS Apellido, 
ISNULL(Nombre, '') AS Nombre, 
ISNULL(Razon_Social, '') AS Razon_Social, 
ISNULL(Email_Web, '') AS Email_Web
FROM Clientes
WHERE
Email_Web = @pEmail_Web
AND Clave_Web = @pClave_Web
AND Activo=1
ORDER BY Id_Cliente DESC

SELECT * FROM #Cliente_Valido

DROP TABLE #Cliente_Valido

END