Try these, May be it will helpfull.
SELECT id,dbo.fn_GetHandlingCodes ()
FROM sampled2 where id = 1
alter FUNCTION dbo.fn_GetHandlingCodes ()
RETURNS VARCHAR(1200)
AS
BEGIN
DECLARE @HandlingCode VARCHAR(20)
DECLARE @HandlingCode1 VARCHAR(20)
DECLARE @ReturnValue VARCHAR(4000)
-- use that fastest cursor methods: local fast_forward
DECLARE code_cursor CURSOR LOCAL fast_forward FOR
SELECT pass,expiry
FROM sampled2
SET @ReturnValue = '' -- set to non null
OPEN code_cursor
FETCH NEXT FROM code_cursor INTO @HandlingCode,@HandlingCode1
WHILE (@@FETCH_STATUS = 0)
BEGIN
SET @ReturnValue = @ReturnValue + @HandlingCode + ', ' + @HandlingCode1 +', '
IF LEN (@ReturnValue) > 1000 BREAK -- avoid overflow
FETCH NEXT FROM code_cursor INTO @HandlingCode,@HandlingCode1
END
CLOSE code_cursor
DEALLOCATE code_cursor
-- remove last delimiter
IF LEN(@ReturnValue) > 1 SET @ReturnValue = SUBSTRING(@ReturnValue,1,LEN(@ReturnValue)-2)
RETURN @ReturnValue
END