if not exists (select name from dbo.sysobjects where name='F_S_GetAvgPrice') begin exec('create FUNCTION dbo.F_S_GetAvgPrice() returns @tbl table(ID int) as begin return end') end