if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_GetCurrentMovenment]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_GetCurrentMovenment]
GO

--create function fn_GetCurrentMovenment (@MovenmentID uniqueidentifier)
--returns uniqueidentifier
--as
--begin
--	declare @ret uniqueidentifier
	
--	select top 1 @ret = MovenmentID from T_MOVENMENT with(nolock)
--		where type_ = 1028 and MedicalcardRegistration = @MovenmentID
--		order by TimeMovenment desc
		
--	if @ret is null return @MovenmentID
--	return @ret
--end