SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MEDWEB_GECMISAMELIYATLAR]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].MEDWEB_GECMISAMELIYATLAR
GO

CREATE FUNCTION dbo.MEDWEB_GECMISAMELIYATLAR(@HKIMLIKID int,@SUBEID int) 
RETURNS @retGecmisAmeliyatlar TABLE 
(
	BOLUMADI nvarchar(100),
	DRADI nvarchar(50),
	ITARIH datetime,
	ISLEMADI nvarchar(150)
)
AS
BEGIN
	INSERT INTO @retGecmisAmeliyatlar
	SELECT LUYGBOLUM, LUYGDRADI, ITARIH, LITEMADI FROM VWAMELIYAT WHERE HKIMLIKID  = @HKIMLIKID AND SUBEID = @SUBEID
    ORDER BY HAMELIYATID DESC
	RETURN
END
GO
