SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

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

CREATE FUNCTION dbo.MEDWEB_GECMISMUAYENELER(@HKIMLIKID int,@SUBEID int) 
RETURNS @retGecmisMuayeneler TABLE 
(
	BOLUMADI nvarchar(100),
	DRADI nvarchar(50),
	ITARIH datetime,
	ISLEMADI nvarchar(150)
)
AS
BEGIN
	INSERT INTO @retGecmisMuayeneler
	SELECT UYGBOLUM, UYGDRADI, ITARIH, ITEMADI FROM VWMUAYENEISL WHERE HKIMLIKID  = @HKIMLIKID AND SUBEID = @SUBEID
	ORDER BY HMUAYENEISLID DESC
    RETURN
END
GO
