
ALTER PROCEDURE [dbo].[MEDWEB_RANDEVUIPTAL] @HKIMLIKID int, @RANDEVUID int
AS
BEGIN
	SET NOCOUNT ON
	DECLARE 
	  @RTARIHSAAT datetime,
	  @RANDDURUMID int,
	  @HMUAYENEISLID int,
	  @Sonuc int
    SET @Sonuc = 0
    SELECT @RTARIHSAAT=RTARIHSAAT, @RANDDURUMID=RANDDURUMID, @HMUAYENEISLID=HMUAYENEISLID 
    FROM HRANDEVU 
    WHERE KIMLIKID = @HKIMLIKID AND RANDEVUID = @RANDEVUID 
    IF @@ROWCOUNT =0 
    BEGIN
		SET @SONUC = 1
    END
    ELSE IF @RTARIHSAAT < GETDATE()
    BEGIN
		SET @SONUC = 2
    END
    ELSE IF NOT @RANDDURUMID IN (1,7)
    BEGIN
		SET @SONUC = 3
    END
    ELSE IF @HMUAYENEISLID IS NOT NULL
    BEGIN
		SET @SONUC = 4
    END
    ELSE
    BEGIN
		UPDATE HRANDEVU SET RANDDURUMID = 6, SGTARIH = GETDATE()
		WHERE KIMLIKID = @HKIMLIKID AND RANDEVUID = @RANDEVUID 
    END
    SELECT @Sonuc
    RETURN
END
