Try This:
CREATE FUNCTION dbo.MyFunction
(@ID int)
returns varchar(2000)
as
begin
declare @rtrn varchar(2000)
declare @temp varchar(500)
declare @rowcount int
set @temp = ''
set @rowcount = 1
set @rtrn = ''
while(@rowcount > 0)
begin
select top 1 @temp = [Name]
from MyTable
where [id]...