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

--create function [dbo].fn_GetResearchCurrentCost (@ResearchID uniqueidentifier, @OnDate datetime)
--returns decimal(12,2)
--as
--begin

--if @OnDate is null set @OnDate = getdate()

--return (
--	select top 1
--		Cost
--	from
--		T_RESEARCH_COST with(nolock)
--	where
--		Research = @ResearchID
--			and
--		datediff(day, [Date], @OnDate) >= 0
--	order by
--		Date desc
--)
--end
--GO