IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPWEB_RECETELER]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPWEB_RECETELER
GO

CREATE PROCEDURE [dbo].[SPWEB_RECETELER]
@kisino NVARCHAR(30), @tumu BIT
AS
BEGIN
	DECLARE @HKIMLIKID INT = dbo.FN_BASIT_ID_SIFRE_AC(@kisino)
	EXEC SPWEB_LOGLA 'receteler',@HKIMLIKID,'Reçete listesini çekti',''
	SELECT TOP (CASE WHEN @tumu=1 THEN 5000 ELSE 50 END)  HRECETEID AS receteno, BOLUMADI AS bolum, DRADI AS doktor, HRECTARIH AS recetetarihi, 
	MdlEreceteNo AS mdlreceteno, SUBEID AS subeno, (SELECT SUBEADI FROM SUBELER WITH(NOLOCK) WHERE SUBEID=VWRECETE.SUBEID) AS sube FROM VWRECETE WITH(NOLOCK) WHERE HKIMLIKID  = @HKIMLIKID ORDER BY HRECETEID DESC
END
GO

IF EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] = N'mediwebuser')
BEGIN
	BEGIN TRY
		GRANT EXECUTE ON [dbo].[SPWEB_RECETELER] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO


