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

CREATE PROCEDURE [dbo].[SPWEB_DOKTORRESIM]
@doktorid INT
AS
BEGIN
	--EXEC SPWEB_LOGLA 'subeler',@kisino,'Şube listesini çekti',''
	DECLARE @img1 varbinary(max)
	SET @img1=(	SELECT TOP 1 UFOTO AS resim
				FROM	UFOTOGRAF UF WITH(NOLOCK)
				JOIN	[USER] U WITH(NOLOCK) ON U.KODU = UF.KODU	
				WHERE	U.DRID=@doktorid AND UF.UFOTO IS NOT NULL)

	SELECT TOP 1 CAST('' AS XML).value('xs:base64Binary(sql:variable("@img1"))','VARCHAR(MAX)') AS resim where @img1 IS NOT NULL

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_DOKTORRESIM] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO




