IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetEhrRusM00002]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_GetEhrRusM00002]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Marat Zigangaraev
-- Create date: 2014-03-06
-- Description:	Возвращает справочник EHR_RUS_M00002
-- =============================================
CREATE FUNCTION [dbo].[fn_GetEhrRusM00002] 
(
	@PatientBenefitsDirectionDrugsID uniqueidentifier
)
RETURNS uniqueidentifier
AS
BEGIN
	RETURN 
	(
		Select (Select Top 1 EhrRusID From [EHR].T_EHR_RUS_M00002 e Where e.CodeEHR = CodeLS)
		From [AKUZ].T_PATIENT_BENEFITS_DIRECTION_DRUGS d
		Where d.PatientBenefitsDirectionDrugsID = @PatientBenefitsDirectionDrugsID
	)
END
GO
